Subversion Repositories Kolibri OS

Rev

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