-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogo_syntax.gSyntax
More file actions
113 lines (103 loc) · 2.99 KB
/
logo_syntax.gSyntax
File metadata and controls
113 lines (103 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
syntax logo_syntax ("logo_lexique.gLexique") :
import "logo_options.gOption" ;
import "logo_semantics.gSemantics" ;
# Règle régissant la boucle principale
rule <start_symbol> :
$PROGRAM$ ;
@routineMap tableRoutines [emptyMap] ;
@instructionList listeInstructions [emptyList] ;
repeat
while
<routine_definition> !?tableRoutines;
end repeat ;
$BEGIN$ ;
<instruction_list> !tableRoutines !?listeInstructions;
$END$ ;
$.$ ;
@bool penDown := false ;
@double x := 0.0 ;
@double y := 0.0 ;
@double angle := 0.0 ; # Angle en degrés
@string SVGInstructionString := "" ;
foreach listeInstructions do
[mInstruction codeDisplay !?penDown !?x !?y !?angle !?SVGInstructionString] ;
end foreach ;
const @string sourceFilePath := [@string stringWithSourceFilePath] ;
@string code := [filewrapper generationTemplate.svg
![sourceFilePath lastPathComponent]
!SVGInstructionString
] ;
[code writeToFile ![sourceFilePath stringByDeletingPathExtension] . ".svg"] ;
end rule ;
# On régit les définitions de routine
rule <routine_definition>
?!@routineMap tableRoutines:
@instructionList listeInstructionsRoutines [emptyList] ;
$ROUTINE$;
$identifier$?@lstring routine_name;
# log routine_name ;
$BEGIN$ ;
<instruction_list> !tableRoutines !?listeInstructionsRoutines;
$END$ ;
[!?tableRoutines insertKey !routine_name !listeInstructionsRoutines] ;
end rule;
# Règle de la liste des instructions (routine ou programme)
rule <instruction_list>
??@routineMap tableRoutines ?!@instructionList listeInstructions:
repeat
while
<forward> !?listeInstructions;
while
<rotate> !?listeInstructions;
while
<pen> !?listeInstructions;
while
<call> !tableRoutines !?listeInstructions;
end repeat;
end rule;
rule <forward> ?!@instructionList listeInstructions:
$FORWARD$;
$integer$?@luint valeurLength;
# log forward_int ;
@instruction instr_forward := [@forward new !valeurLength] ;
listeInstructions += !instr_forward;
$;$;
end rule;
rule <rotate> ?!@instructionList listeInstructions:
$ROTATE$;
$integer$?@luint valeurAngle;
# log rotate_int ;
@instruction instr_rotate := [@rotate new !valeurAngle] ;
listeInstructions += !instr_rotate;
$;$;
end rule;
rule <pen> ?!@instructionList listeInstructions:
$PEN$;
repeat
while
$UP$; $;$; @instruction instr_pen_up := [@penUp new] ; listeInstructions += !instr_pen_up;
while
$DOWN$; $;$; @instruction instr_pen_down := [@penDown new] ; listeInstructions += !instr_pen_down;
end repeat;
end rule;
rule <call>
??@routineMap tableRoutines ?!@instructionList listeCouranteInstructions:
@instructionList listeInstructionsRoutines [emptyList] ;
$CALL$;
$identifier$?@lstring routine_name_call;
[tableRoutines searchKey !routine_name_call ?listeInstructionsRoutines] ;
foreach listeInstructionsRoutines do
listeCouranteInstructions += !mInstruction ;
end foreach ;
# log routine_name_call ;
$;$;
end rule;
filewrapper generationTemplate in "." {
} {
} {
template svg "logo_svg.gTemplate"
?@string TITLE
?@string DRAWINGS
;
}
end syntax ;