-
Notifications
You must be signed in to change notification settings - Fork 3
/
microalg_export_microalg.l
203 lines (193 loc) · 6.27 KB
/
microalg_export_microalg.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
(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)
(let (!lines_with_final_NIL (mapcar pack (split (chop !instr) "^J"))
!lines (reverse (cdr (reverse !lines_with_final_NIL))))
(mapcar (list '(!line)
(list 'pack " " '!line "^J")) !lines)
)
)
(de + @ (pack "(+ " (glue " " (rest)) ")"))
(de - (A B) (pack "(- " A " " B ")"))
(de * @ (pack "(* " (glue " " (rest)) ")"))
(de / (A B) (pack "(/ " A " " B ")"))
(de % (A B) (pack "(% " A " " B ")"))
(de ^ (A B) (pack "(\^ " A " " B ")"))
(de Racine (A) (pack "(Racine " A ")"))
(de !!! (comz) (pack "(!!! " (if comz @ "\"\"") ")^J"))
(de Afficher (obj) (pack "(Afficher " 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 ...)
(pack "(Declarer "
(glue " " !vars)
" De_type \""
!type "\")^J"
)
)
)
(setq Déclarer 'Declarer)
(de Concatener @
(let (!arg_lst (rest)
!space_separated (glue " " !arg_lst)
!length (length !space_separated))
(if (le0 (dec '!length 30)) # à la louche
(pack "(Concatener " !space_separated ")")
(pack "^J (Concatener^J "
(glue "^J " !arg_lst) "^J"
" )"
"^J")
)
)
)
(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 "(Affecter_a " !var " " !val ")^J")))
(setq Affecter_à 'Affecter_a)
(de Entier@ (A B) (pack "(Entier@ " A " " B ")"))
(setq Vrai "Vrai")
(setq Faux "Faux")
(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
"(Si " (eval condition) "^J"
" Alors^J"
(mapcar 'eval bloc_vrai)
(if bloc_faux
(pack " Sinon^J"
(mapcar 'eval bloc_faux)))
")^J"
)
)
)
(de Non (bool) (pack "(Non " bool ")"))
(de Et @ (pack "(Et " (glue " " (rest)) ")"))
(de Ou @ (pack "(Ou " (glue " " (rest)) ")"))
(de Tant_que arg_lst (let (!cond (car arg_lst)
!mot-clef (cadr arg_lst)
!corps (cddr arg_lst))
(pack
"(Tant_que " (eval !cond) "^J"
" Faire^J"
(mapcar 'eval !corps)
")^J"
)
)
)
(de Faire arg_lst (let (!splitted (split arg_lst 'Tant_que)
!corps (car !splitted)
!cond (caadr !splitted))
(pack
"(Faire^J"
(mapcar 'eval !corps)
" Tant_que " (eval !cond) "^J"
")^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 "(Liste " (glue " " (rest)) ")"))
(de 1000Cosinus (angle) (pack "(1000Cosinus " angle ")"))
(de 1000Sinus (angle) (pack "(1000Sinus " angle ")"))
(de Longueur (A) (pack "(Longueur " A ")"))
(de Nieme (obj idx) (pack "(Nieme " obj " " idx ")"))
(de Millisecondes () "(Millisecondes)")
(de RAZ () "(RAZ)^J")
(de Cercle inputs
(let (origine (eval (car inputs))
r (eval (cadr inputs)))
(pack "(Cercle " origine " " r ")^J")
)
)
(de Contour (coul)
(pack "(Contour " coul ")^J"))
(de Remplissage (coul)
(pack "(Remplissage " coul ")^J"))
(de Ellipse inputs
(let (origine (eval (car inputs))
r1 (eval (cadr inputs))
r2 (eval (caddr inputs)))
(pack "(Ellipse " origine " " r1 " " r2 ")^J")
)
)
(de Epaisseur (e)
(pack "(Epaisseur " e ")^J")
)
(de Rectangle (p1 p2)
(pack "(Rectangle " p1 " " p2 ")^J")
)
(de Segment (p1 p2)
(pack "(Segment " p1 " " p2 ")^J")
)
(de Triangle (p1 p2 p3)
(pack "(Triangle " p1 " " p2 " " p3 ")^J")
)
(de Repere (xmin xmax ymin ymax xscl yscl)
(pack "(Repere " xmin " " xmax " " ymin " " ymax
(if xscl (pack " " xscl " " yscl))
")^J"
)
)
(de Tete (obj) (pack "(Tete " obj ")"))
(de Queue (obj) (pack "(Queue " obj ")"))
(de Ajouter_a (obj val) (pack "(Ajouter_a " obj " " val ")"))
(de Retirer_de (obj) (pack "(Retirer_de " obj ")"))
# En_position
(de Nieme@ (obj) (pack "(Nieme@ " obj ")"))
(de Texte (obj) (pack "(Texte " obj ")"))
(de Nombre (obj) (pack "(Nombre " obj ")"))
# Alors Sinon
(de Repeter !inputs
(let (nb (eval (car !inputs))
prg (cddr !inputs))
(pack "(Repeter " nb " Fois^J"
(mapcar 'eval prg)
")^J"
)
)
)
(setq Répéter 'Repeter)
(de ... () "(...)")
(de Demander () (pack "(Demander)"))
(de Demander_un_nombre () (pack "(Demander_un_nombre)"))
(de Demander_un_nombre_pour !arg_lst
(let (!var (cadr (car !arg_lst))) # var name is in (Variable ...)
(pack "(Demander_un_nombre_pour " !var ")^J")
)
)
(de Initialiser@ (n) (pack "(Initialiser@ " n ")^J"))
(de Type (obj) (pack "(Type " obj ")"))
(de AV (n) (pack "(AV " n ")^J"))
(de BC () (pack "(BC)^J"))
(de LC () (pack "(LC)^J"))
(de TD (a) (pack "(TD" (if a (pack " " @)) ")^J"))
(de TG (a) (pack "(TG" (if a (pack " " @)) ")^J"))
(de !no_export (cmd)
(pack "-- La commande " cmd " ne peut être exportée. --^J"))
(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 "?"))
(setq Rien "Rien")