Rev 4882 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4865 | eAndrew | 1 | macro test_err |
2 | { local ..not_error |
||
3 | cmp [error_n], 0 |
||
4 | je ..not_error |
||
5 | ret |
||
6 | ..not_error: |
||
7 | } |
||
8 | |||
9 | macro set_err err |
||
10 | { |
||
11 | mov [error_n], err |
||
12 | ret |
||
13 | } |
||
14 | |||
15 | ; --------------------------- |
||
16 | |||
17 | proc parse |
||
18 | mov [exp_pos], 0 |
||
4875 | eAndrew | 19 | stdcall skip_spaces |
20 | |||
21 | mov ebx, exp |
||
22 | add ebx, [exp_pos] |
||
23 | cmp [ebx], byte 0 |
||
24 | je .null_exp |
||
25 | |||
26 | mov [exp_lvl], 0 |
||
4865 | eAndrew | 27 | mov [error_n], 0 |
28 | stdcall parse_lvl0 |
||
29 | ret |
||
4875 | eAndrew | 30 | |
31 | .null_exp: |
||
32 | mov eax, 0 |
||
33 | ret |
||
4865 | eAndrew | 34 | endp |
35 | |||
36 | ; --------------------------- |
||
37 | |||
38 | proc parse_lvl0 uses ebx ecx |
||
39 | test_err |
||
40 | stdcall parse_lvl1 |
||
41 | test_err |
||
42 | @@: |
||
43 | mov ebx, exp |
||
44 | add ebx, [exp_pos] |
||
45 | cmp [ebx], byte 0 |
||
46 | je .end |
||
47 | cmp [ebx], byte ")" |
||
4875 | eAndrew | 48 | je .brk_end |
4943 | eAndrew | 49 | cmp [ebx], byte "|" |
50 | je .abs_end |
||
4865 | eAndrew | 51 | inc [exp_pos] |
52 | cmp [ebx], byte "+" |
||
53 | jne .not_add |
||
54 | mov ecx, eax |
||
55 | stdcall parse_lvl1 |
||
56 | test_err |
||
57 | add eax, ecx |
||
58 | jmp @b |
||
59 | .not_add: |
||
60 | cmp [ebx], byte "-" |
||
4875 | eAndrew | 61 | jne .unexp_char |
4865 | eAndrew | 62 | mov ecx, eax |
63 | stdcall parse_lvl1 |
||
64 | test_err |
||
65 | sub ecx, eax |
||
66 | mov eax, ecx |
||
67 | jmp @b |
||
4875 | eAndrew | 68 | .brk_end: |
69 | cmp [exp_lvl], 0 |
||
70 | jne @f |
||
71 | set_err 3 |
||
72 | @@: |
||
73 | dec [exp_lvl] |
||
4943 | eAndrew | 74 | jmp .end |
75 | .abs_end: |
||
76 | cmp [abs_lvl], 0 |
||
77 | jne @f |
||
78 | set_err 5 |
||
79 | @@: |
||
80 | dec [abs_lvl] |
||
4865 | eAndrew | 81 | .end: |
82 | ret |
||
4875 | eAndrew | 83 | .unexp_char: |
84 | set_err 4 |
||
4865 | eAndrew | 85 | endp |
86 | |||
87 | ; --------------------------- |
||
88 | |||
89 | proc parse_lvl1 uses ebx ecx edx |
||
90 | test_err |
||
91 | stdcall parse_lvl2 |
||
92 | test_err |
||
93 | @@: |
||
94 | mov ebx, exp |
||
95 | add ebx, [exp_pos] |
||
96 | cmp [ebx], byte 0 |
||
97 | je .end |
||
98 | cmp [ebx], byte "*" |
||
99 | jne .not_mul |
||
4875 | eAndrew | 100 | inc [exp_pos] |
4865 | eAndrew | 101 | mov ecx, eax |
102 | stdcall parse_lvl2 |
||
103 | test_err |
||
104 | imul ecx, eax |
||
105 | mov eax, ecx |
||
106 | jmp @b |
||
107 | .not_mul: |
||
108 | cmp [ebx], byte "/" |
||
109 | je .div_or_mod |
||
110 | cmp [ebx], byte "%" |
||
111 | je .div_or_mod |
||
112 | jmp .end |
||
113 | .div_or_mod: |
||
4875 | eAndrew | 114 | inc [exp_pos] |
4865 | eAndrew | 115 | mov ecx, eax |
116 | stdcall parse_lvl2 |
||
117 | test_err |
||
118 | cmp eax, 0 |
||
119 | jne .not_null |
||
120 | set_err 1 |
||
121 | .not_null: |
||
122 | xchg ecx, eax |
||
123 | cdq |
||
124 | div ecx |
||
125 | cmp [ebx], byte "%" |
||
126 | je .mod |
||
127 | jmp @b |
||
128 | .mod: |
||
129 | mov eax, edx |
||
130 | jmp @b |
||
131 | .end: |
||
132 | ret |
||
133 | endp |
||
134 | |||
135 | ; --------------------------- |
||
136 | |||
4875 | eAndrew | 137 | proc parse_lvl2 uses ebx ecx edx |
4865 | eAndrew | 138 | test_err |
4875 | eAndrew | 139 | stdcall parse_lvl3 |
140 | test_err |
||
141 | @@: |
||
142 | mov ebx, exp |
||
143 | add ebx, [exp_pos] |
||
144 | cmp [ebx], byte 0 |
||
145 | je .end |
||
146 | cmp [ebx], byte "^" |
||
147 | jne .end |
||
148 | inc [exp_pos] |
||
149 | mov ecx, eax |
||
150 | stdcall parse_lvl2 |
||
151 | test_err |
||
152 | stdcall c_power |
||
153 | jmp @b |
||
154 | .end: |
||
155 | ret |
||
156 | endp |
||
157 | |||
158 | ; --------------------------- |
||
159 | |||
4882 | eAndrew | 160 | proc parse_lvl3 uses ebx ecx edx |
4875 | eAndrew | 161 | test_err |
4865 | eAndrew | 162 | stdcall skip_spaces |
163 | mov ebx, exp |
||
164 | add ebx, [exp_pos] |
||
165 | cmp [ebx], byte 48 |
||
166 | jl @f |
||
167 | cmp [ebx], byte 57 |
||
168 | jg @f |
||
4875 | eAndrew | 169 | stdcall parse_lvl4 |
4865 | eAndrew | 170 | jmp .end |
171 | @@: |
||
4882 | eAndrew | 172 | cmp [ebx], byte 97 |
173 | jl @f |
||
174 | cmp [ebx], byte 122 |
||
175 | jg @f |
||
176 | jmp .parse_func |
||
177 | @@: |
||
4865 | eAndrew | 178 | inc [exp_pos] |
179 | cmp [ebx], byte "(" |
||
180 | jne @f |
||
4875 | eAndrew | 181 | inc [exp_lvl] |
4865 | eAndrew | 182 | stdcall parse_lvl0 |
183 | test_err |
||
4875 | eAndrew | 184 | mov ebx, exp |
185 | add ebx, [exp_pos] |
||
186 | cmp [ebx], byte ")" |
||
187 | je .brk_ok |
||
188 | set_err 2 |
||
189 | .brk_ok: |
||
4865 | eAndrew | 190 | inc [exp_pos] |
191 | jmp .end |
||
192 | @@: |
||
4943 | eAndrew | 193 | cmp [ebx], byte "|" |
194 | jne @f |
||
195 | inc [abs_lvl] |
||
196 | stdcall parse_lvl0 |
||
197 | test_err |
||
198 | mov ebx, exp |
||
199 | add ebx, [exp_pos] |
||
200 | cmp [ebx], byte "|" |
||
201 | je .abs_ok |
||
202 | set_err 5 |
||
203 | .abs_ok: |
||
204 | inc [exp_pos] |
||
205 | cmp eax, 0 |
||
206 | jge .end |
||
207 | not eax |
||
208 | inc eax |
||
209 | jmp .end |
||
210 | @@: |
||
4865 | eAndrew | 211 | cmp [ebx], byte "+" |
212 | jne @f |
||
4875 | eAndrew | 213 | stdcall parse_lvl3 |
4865 | eAndrew | 214 | test_err |
215 | jmp .end |
||
216 | @@: |
||
217 | cmp [ebx], byte "-" |
||
4875 | eAndrew | 218 | jne .unexp_char |
219 | stdcall parse_lvl3 |
||
4865 | eAndrew | 220 | test_err |
221 | neg eax |
||
222 | .end: |
||
223 | stdcall skip_spaces |
||
224 | ret |
||
4875 | eAndrew | 225 | .unexp_char: |
226 | set_err 4 |
||
4882 | eAndrew | 227 | .parse_func: |
228 | mov ecx, 0 |
||
229 | mov dl, 0 |
||
230 | @@: |
||
231 | cmp [ebx], byte 97 |
||
232 | jl @f |
||
233 | cmp [ebx], byte 122 |
||
234 | jg @f |
||
235 | cmp dl, 4 |
||
236 | je .unexp_char |
||
237 | shl ecx, 8 |
||
238 | mov cl, [ebx] |
||
239 | inc dl |
||
240 | inc ebx |
||
241 | inc [exp_pos] |
||
242 | jmp @b |
||
243 | @@: |
||
244 | cmp ecx, "cni" |
||
245 | je @f |
||
246 | cmp ecx, "ced" |
||
247 | je @f |
||
248 | cmp ecx, "sba" |
||
249 | je @f |
||
250 | cmp ecx, "rqs" |
||
251 | je @f |
||
252 | jmp .unexp_char |
||
253 | @@: |
||
254 | stdcall skip_spaces |
||
255 | mov ebx, exp |
||
256 | add ebx, [exp_pos] |
||
257 | cmp [ebx], byte "(" |
||
258 | jne .unexp_char |
||
259 | inc [exp_lvl] |
||
260 | inc [exp_pos] |
||
261 | stdcall parse_lvl0 |
||
262 | test_err |
||
263 | mov ebx, exp |
||
264 | add ebx, [exp_pos] |
||
265 | cmp [ebx], byte ")" |
||
266 | je @f |
||
267 | set_err 2 |
||
268 | @@: |
||
269 | inc [exp_pos] |
||
270 | stdcall skip_spaces |
||
271 | cmp ecx, "cni" |
||
272 | jne @f |
||
273 | inc eax |
||
274 | jmp .f_end |
||
275 | @@: |
||
276 | cmp ecx, "ced" |
||
277 | jne @f |
||
278 | dec eax |
||
279 | jmp .f_end |
||
280 | @@: |
||
281 | cmp ecx, "sba" |
||
282 | jne @f |
||
283 | mov ecx, eax |
||
284 | shr ecx, 31 |
||
285 | cmp cl, 1 |
||
286 | jne .f_end |
||
287 | not eax |
||
288 | inc eax |
||
289 | jmp .f_end |
||
290 | @@: |
||
291 | cmp ecx, "rqs" |
||
292 | jne @f |
||
293 | imul eax, eax |
||
294 | jmp .f_end |
||
295 | @@: |
||
296 | jmp .unexp_char |
||
297 | .f_end: |
||
298 | ret |
||
4865 | eAndrew | 299 | endp |
300 | |||
301 | ; --------------------------- |
||
302 | |||
4875 | eAndrew | 303 | proc parse_lvl4 uses ebx ecx |
4882 | eAndrew | 304 | stdcall skip_spaces |
4875 | eAndrew | 305 | stdcall parse_lvl5 |
4882 | eAndrew | 306 | stdcall skip_spaces |
4875 | eAndrew | 307 | @@: |
308 | mov ebx, exp |
||
309 | add ebx, [exp_pos] |
||
310 | cmp [ebx], byte 0 |
||
311 | je .end |
||
312 | cmp [ebx], byte "^" |
||
313 | jne .end |
||
314 | inc [exp_pos] |
||
4882 | eAndrew | 315 | stdcall skip_spaces |
4875 | eAndrew | 316 | mov ecx, eax |
317 | mov ebx, exp |
||
318 | add ebx, [exp_pos] |
||
319 | cmp [ebx], byte 48 |
||
320 | jl .unexp_char |
||
321 | cmp [ebx], byte 57 |
||
322 | jg .unexp_char |
||
323 | stdcall parse_lvl4 |
||
324 | stdcall c_power |
||
325 | jmp @b |
||
326 | .end: |
||
327 | ret |
||
328 | .unexp_char: |
||
329 | set_err 4 |
||
330 | endp |
||
331 | |||
332 | ; --------------------------- |
||
333 | |||
334 | proc parse_lvl5 uses ebx ecx |
||
4865 | eAndrew | 335 | sub eax, eax |
336 | sub ecx, ecx |
||
337 | mov ebx, exp |
||
338 | add ebx, [exp_pos] |
||
339 | @@: |
||
340 | cmp [ebx], byte 0 |
||
341 | je @f |
||
342 | cmp [ebx], byte 48 |
||
343 | jl @f |
||
344 | cmp [ebx], byte 57 |
||
345 | jg @f |
||
346 | imul eax, 10 |
||
347 | mov cl, [ebx] |
||
348 | add eax, ecx |
||
349 | sub eax, 48 |
||
350 | inc ebx |
||
351 | inc [exp_pos] |
||
352 | jmp @b |
||
353 | @@: |
||
354 | ret |
||
355 | endp |
||
356 | |||
357 | ; --------------------------- |
||
358 | |||
359 | proc skip_spaces uses ebx |
||
360 | mov ebx, exp |
||
361 | add ebx, [exp_pos] |
||
362 | @@: |
||
363 | cmp [ebx], byte " " |
||
364 | jne @f |
||
365 | inc ebx |
||
366 | inc [exp_pos] |
||
367 | jmp @b |
||
368 | @@: |
||
369 | ret |
||
4875 | eAndrew | 370 | endp |
371 | |||
372 | ; --------------------------- |
||
373 | |||
374 | proc c_power uses ebx |
||
375 | mov ebx, eax |
||
376 | mov eax, 1 |
||
377 | @@: |
||
378 | cmp ebx, 0 |
||
379 | je @f |
||
380 | imul eax, ecx |
||
381 | dec ebx |
||
382 | jmp @b |
||
383 | @@: |
||
384 | ret |
||
385 | endp |
||
386 | |||
387 | ; --------------------------- |
||
388 | |||
389 | proc convert_to_str uses ebx ecx edx esi edi, _num, _str |
||
390 | mov eax, [_num] |
||
391 | mov esi, [_str] |
||
392 | mov edi, 0 |
||
393 | mov ecx, eax |
||
394 | and ecx, 1 shl 31 |
||
395 | cmp ecx, 0 |
||
396 | je @f |
||
397 | mov [esi], byte "-" |
||
398 | inc esi |
||
399 | inc edi |
||
400 | not eax |
||
401 | inc eax |
||
402 | @@: |
||
403 | mov ebx, 10 |
||
404 | xor ecx, ecx |
||
405 | @@: |
||
406 | xor edx, edx |
||
407 | div ebx |
||
408 | push edx |
||
409 | inc ecx |
||
410 | inc edi |
||
411 | cmp eax, 0 |
||
412 | jne @b |
||
413 | @@: |
||
414 | pop eax |
||
415 | add al, "0" |
||
416 | mov [esi], al |
||
417 | inc esi |
||
418 | loop @b |
||
419 | mov [esi], byte 0 |
||
420 | mov eax, edi |
||
421 | ret |
||
4865 | eAndrew | 422 | endp |