-
Notifications
You must be signed in to change notification settings - Fork 3
/
microalg_export_processing.l
205 lines (194 loc) · 6.41 KB
/
microalg_export_processing.l
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
(de Litteral (content)
(cond
((num? content) content)
((str? content) (pack "\"" content "\""))
(T "Littéral de type inconnu.")
))
(de Variable inputs
(let (nom_var (car inputs))
(if nom_var nom_var "")
)
)
(de indent (!instr)
(indent_std !instr))
(de + (A B) (pack "(" A "+" B ")"))
(de - (A B) (pack "(" A "-" B ")"))
(de * (A B) (pack "(" A "*" B ")"))
(de / (A B) (pack "(" A "/" B ")"))
(de % (A B) (pack "(" A "%" B ")"))
(de ^ (A B) (pack "pow(" A ", " B ")"))
(de Racine (A) (pack "sqrt(" A ")"))
(de !!! (comz) (pack "// " (cdr (reverse (cdr (reverse (chop comz))))) "^J"))
(de Afficher (obj) (pack "println(" obj ");^J"))
(de Declarer !arg_lst
(let (!splitted (split !arg_lst 'De_type)
!vars (mapcar 'cadr (car !splitted)) # var name is in (Variable ...)
!type (cadr (caadr !splitted))) # type is in (Litteral ...)
(cond
((not (<> !type "nombre"))
(pack "float " (glue ", " !vars) ";^J"))
((not (<> !type "texte"))
(pack "String " (glue ", " !vars) ";^J"))
(T (pack "Impossible de gérer le type « " !type " » avec Processing.^J"))
)
)
)
(setq Déclarer 'Declarer)
(de Concatener @ (glue " + " (rest)))
(setq Concaténer 'Concatener)
(de Affecter_a !arg_lst
(let (!var (cadr (car !arg_lst)) # var name is in (Variable ...)
!val (eval (cadr !arg_lst)))
(pack !var " = " !val ";^J")))
(setq Affecter_à 'Affecter_a)
(de Entier@ (A B) (pack "int(" A " + random(" B "-" A "+1))"))
(setq Vrai "true")
(setq Faux "false")
(setq Rien "null")
(de Si arg_lst (let (condition (car arg_lst)
kw_alors (cadr arg_lst)
splitted (split (cddr arg_lst) 'Sinon)
bloc_vrai (car splitted)
bloc_faux (cadr splitted))
(pack
"if (" (eval condition) ")^J" "{^J"
(mapcar 'eval bloc_vrai)
(if bloc_faux (pack "} else {^J" (mapcar 'eval bloc_faux)))
"}^J"
)
)
)
(de Non (bool) (pack "!(" bool ")"))
(de Et @ (pack "(" (glue " && " (rest)) ")"))
(de Ou ? (pack "(" (glue " || " (rest)) ")"))
(de Tant_que arg_lst (let (!cond (car arg_lst)
!mot-clef (cadr arg_lst)
!corps (cddr arg_lst))
(pack
"while (" (eval !cond) ") {^J"
(mapcar 'eval !corps)
"}^J"
)
)
)
(de Faire arg_lst (let (!splitted (split arg_lst 'Tant_que)
!corps (car !splitted)
!cond (caadr !splitted))
(pack
"do {^J"
(mapcar 'eval !corps)
"} while (" (eval !cond) ");^J"
)
)
)
(de = (A B) (pack "(" A " == " B ")"))
(de < (A B) (pack "(" A " < " B ")"))
(de <= (A B) (pack "(" A " <= " B ")"))
(de > (A B) (pack "(" A " > " B ")"))
(de >= (A B) (pack "(" A " >= " B ")"))
(de =/ (A B) (pack "(" A " != " B ")"))
(de Liste @ (pack "[" (glue ", " (rest)) "]"))
(de 1000Cosinus (angle) (pack "cos(radians(" angle "))"))
(de 1000Sinus (angle) (pack "sin(radians(" angle "))"))
(de Longueur (A) (pack A ".length"))
(de Nieme (obj idx) (pack obj "[" idx "-1]"))
(de Millisecondes () "millis()")
(de RAZ () "background(255);^J")
(de Cercle inputs
(let (origine (car inputs)
orig_x (eval (cadr origine))
orig_y (eval (caddr origine))
r (eval (cadr inputs)))
(pack "ellipse(" orig_x ", " orig_y ", 2*" r ", 2*" r ");^J")
)
)
(de Contour inputs
(let (couleur (car inputs)
R (eval (cadr couleur))
V (eval (caddr couleur))
B (eval (cadddr couleur)))
(pack "stroke(" R ", " V ", " B ");^J")))
(de Remplissage inputs
(let (couleur (car inputs)
R (eval (cadr couleur))
V (eval (caddr couleur))
B (eval (cadddr couleur)))
(pack "fill(" R ", " V ", " B ");^J")))
(de Ellipse inputs
(let (origine (car inputs)
orig_x (eval (cadr origine))
orig_y (eval (caddr origine))
r1 (eval (cadr inputs))
r2 (eval (caddr inputs)))
(pack "ellipse(" orig_x ", " orig_y ", 2*" r1 ", 2*" r2 ");^J")
)
)
(de Epaisseur inputs
(let (e (eval (cadr (car inputs))))
(pack "strokeWeight(" e ");^J")
)
)
(de Rectangle inputs
(let (p1 (car inputs)
p2 (cadr inputs)
x1 (eval (cadr p1))
y1 (eval (caddr p1))
x2 (eval (cadr p2))
y2 (eval (caddr p2)))
(pack "rect(" x1 ", " y1 ", " x2 ", " y2 ");^J")
)
)
(de Segment inputs
(let (p1 (car inputs)
p2 (cadr inputs)
x1 (eval (cadr p1))
y1 (eval (caddr p1))
x2 (eval (cadr p2))
y2 (eval (caddr p2)))
(pack "line(" x1 ", " y1 ", " x2 ", " y2 ");^J")
)
)
(de Triangle inputs
(let (p1 (car inputs)
p2 (cadr inputs)
p3 (caddr inputs)
x1 (eval (cadr p1))
y1 (eval (caddr p1))
x2 (eval (cadr p2))
y2 (eval (caddr p2))
x3 (eval (cadr p3))
y3 (eval (caddr p3)))
(pack "triangle(" x1 ", " y1 ", " x2 ", " y2 ", " x3 ", " y3 ");^J")
)
)
(de Repere () (!no_export "Repere"))
(de Tete () (!no_export "Tete"))
(de Queue () (!no_export "Queue"))
(de Ajouter_a () (!no_export "Ajouter_a"))
(de Retirer_de () (!no_export "Retirer_de"))
# En_position
(de Nieme@ () (!no_export "Nieme@"))
(de Texte () (!no_export "Texte"))
(de Nombre () (!no_export "Nombre"))
# Alors Sinon
(de Repeter () (!no_export "Repeter"))
(de Répéter () (!no_export "Répéter"))
(de ... () " (...) ")
(de !no_export (cmd)
(pack "-- La commande " cmd " ne peut être exportée. --^J"))
(de Demander () (!no_export "Demander"))
(de Demander_un_nombre () (!no_export "Demander_un_nombre"))
(de Demander_un_nombre_pour () (!no_export "Demander_un_nombre_pour"))
(de Initialiser@ () (!no_export "Initialiser@"))
(de Type () (!no_export "Type"))
(de Definir () (!no_export "Definir"))
(de Définir () (!no_export "Définir"))
(de Retourner () (!no_export "Retourner"))
(de Exemples_de () (!no_export "Exemples_de"))
(de Tester () (!no_export "Tester"))
(de ? () (!no_export "?"))
(de AV () (!no_export "AV"))
(de BC () (!no_export "BC"))
(de LC () (!no_export "LC"))
(de TD () (!no_export "TD"))
(de TG () (!no_export "TG"))