Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/ffcalc/good/ffcm.c @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* FOUR FUNCTION CALCULATOR: FFCALC.SYN */ | |
2 /* | |
3 * AnaGram, A System for Syntax Directed Programming | |
4 * File generated by: ... | |
5 * | |
6 * AnaGram Parsing Engine | |
7 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
8 * | |
9 * This software is provided 'as-is', without any express or implied | |
10 * warranty. In no event will the authors be held liable for any damages | |
11 * arising from the use of this software. | |
12 * | |
13 * Permission is granted to anyone to use this software for any purpose, | |
14 * including commercial applications, and to alter it and redistribute it | |
15 * freely, subject to the following restrictions: | |
16 * | |
17 * 1. The origin of this software must not be misrepresented; you must not | |
18 * claim that you wrote the original software. If you use this software | |
19 * in a product, an acknowledgment in the product documentation would be | |
20 * appreciated but is not required. | |
21 * 2. Altered source versions must be plainly marked as such, and must not be | |
22 * misrepresented as being the original software. | |
23 * 3. This notice may not be removed or altered from any source distribution. | |
24 */ | |
25 | |
26 #ifndef FFCM_H | |
27 #include "ffcm.h" | |
28 #endif | |
29 | |
30 #ifndef FFCM_H | |
31 #error Mismatched header file | |
32 #endif | |
33 | |
34 #include <ctype.h> | |
35 #include <stdio.h> | |
36 | |
37 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
38 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
39 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
40 | |
41 | |
42 | |
43 ffcm_pcb_type ffcm_pcb; | |
44 #define PCB ffcm_pcb | |
45 | |
46 /* Line -, ffcm.syn */ | |
47 /* -- EMBEDDED C ---------------------------------- */ | |
48 double value[64]; /* registers */ | |
49 void main(void) { | |
50 ffcalc(); | |
51 } | |
52 | |
53 #ifndef CONVERT_CASE | |
54 #define CONVERT_CASE(c) (c) | |
55 #endif | |
56 #ifndef TAB_SPACING | |
57 #define TAB_SPACING 8 | |
58 #endif | |
59 | |
60 #define ag_rp_1(x) (printf("%g\n",x)) | |
61 | |
62 static void ag_rp_2(int n, double x) { | |
63 /* Line -, ffcm.syn */ | |
64 printf("%c = %g\n",n+'A',value[n]=x); | |
65 } | |
66 | |
67 #define ag_rp_3(x, t) (x+t) | |
68 | |
69 #define ag_rp_4(x, t) (x-t) | |
70 | |
71 #define ag_rp_5(t, f) (t*f) | |
72 | |
73 #define ag_rp_6(t, f) (t/f) | |
74 | |
75 #define ag_rp_7(n) (value[n]) | |
76 | |
77 #define ag_rp_8(x) (x) | |
78 | |
79 #define ag_rp_9(f) (-f) | |
80 | |
81 #define ag_rp_10(c) (c-'A') | |
82 | |
83 #define ag_rp_11(i, f) (i+f) | |
84 | |
85 #define ag_rp_12(f) (f) | |
86 | |
87 #define ag_rp_13(d) (d-'0') | |
88 | |
89 #define ag_rp_14(x, d) (10*x + d-'0') | |
90 | |
91 #define ag_rp_15(d) ((d-'0')/10.) | |
92 | |
93 #define ag_rp_16(d, f) ((d-'0' + f)/10.) | |
94 | |
95 #define ag_rp_17(c) (n_chars = 0, name[n_chars++]=c) | |
96 | |
97 #define ag_rp_18(c) (name[n_chars++]=c) | |
98 | |
99 | |
100 #define READ_COUNTS | |
101 #define WRITE_COUNTS | |
102 #undef V | |
103 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
104 #undef VS | |
105 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
106 | |
107 #ifndef GET_CONTEXT | |
108 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
109 #endif | |
110 | |
111 typedef enum { | |
112 ag_action_1, | |
113 ag_action_2, | |
114 ag_action_3, | |
115 ag_action_4, | |
116 ag_action_5, | |
117 ag_action_6, | |
118 ag_action_7, | |
119 ag_action_8, | |
120 ag_action_9, | |
121 ag_action_10, | |
122 ag_action_11, | |
123 ag_action_12 | |
124 } ag_parser_action; | |
125 | |
126 | |
127 #ifndef NULL_VALUE_INITIALIZER | |
128 #define NULL_VALUE_INITIALIZER = { 0 } | |
129 #endif | |
130 | |
131 static ffcm_vs_type const ag_null_value NULL_VALUE_INITIALIZER; | |
132 | |
133 static const unsigned char ag_rpx[] = { | |
134 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4, 0, 5, 6, 7, 0, | |
135 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 0, 0, 0, 12, 13, 14, 15, | |
136 16, 17, 18 | |
137 }; | |
138 | |
139 static const unsigned char ag_key_itt[] = { | |
140 0 | |
141 }; | |
142 | |
143 static const unsigned short ag_key_pt[] = { | |
144 0 | |
145 }; | |
146 | |
147 static const unsigned char ag_key_ch[] = { | |
148 0, 47,255, 42,255 | |
149 }; | |
150 | |
151 static const unsigned char ag_key_act[] = { | |
152 0,3,4,3,4 | |
153 }; | |
154 | |
155 static const unsigned char ag_key_parm[] = { | |
156 0, 25, 0, 29, 0 | |
157 }; | |
158 | |
159 static const unsigned char ag_key_jmp[] = { | |
160 0, 0, 0, 2, 0 | |
161 }; | |
162 | |
163 static const unsigned char ag_key_index[] = { | |
164 1, 3, 1, 1, 1, 0, 3, 3, 3, 1, 1, 0, 0, 0, 0, 3, 1, 0, | |
165 1, 0, 0, 0 | |
166 }; | |
167 | |
168 static const unsigned char ag_key_ends[] = { | |
169 42,0, 47,0, | |
170 }; | |
171 #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0) | |
172 | |
173 static const unsigned char ag_tcv[] = { | |
174 9, 39, 39, 39, 39, 39, 39, 39, 39, 39, 24, 42, 24, 24, 24, 39, 39, 39, | |
175 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 24, 39, 39, | |
176 39, 39, 39, 39, 39, 51, 50, 47, 45, 39, 46, 32, 48, 54, 54, 54, 54, 54, | |
177 54, 54, 54, 54, 54, 39, 39, 39, 44, 39, 39, 39, 52, 52, 52, 52, 52, 52, | |
178 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, | |
179 52, 52, 39, 39, 39, 39, 39, 39, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, | |
180 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 39, 39, | |
181 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
182 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
183 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
184 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
185 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
186 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
187 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, | |
188 39, 39, 39, 39, 39 | |
189 }; | |
190 | |
191 #ifndef SYNTAX_ERROR | |
192 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
193 (PCB).error_message, (PCB).line, (PCB).column) | |
194 #endif | |
195 | |
196 #ifndef FIRST_LINE | |
197 #define FIRST_LINE 1 | |
198 #endif | |
199 | |
200 #ifndef FIRST_COLUMN | |
201 #define FIRST_COLUMN 1 | |
202 #endif | |
203 | |
204 #ifndef PARSER_STACK_OVERFLOW | |
205 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
206 "\nParser stack overflow, line %d, column %d\n",\ | |
207 (PCB).line, (PCB).column);} | |
208 #endif | |
209 | |
210 #ifndef REDUCTION_TOKEN_ERROR | |
211 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
212 "\nReduction token error, line %d, column %d\n", \ | |
213 (PCB).line, (PCB).column);} | |
214 #endif | |
215 | |
216 | |
217 typedef enum | |
218 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
219 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
220 | |
221 #ifndef GET_INPUT | |
222 #define GET_INPUT ((PCB).input_code = getchar()) | |
223 #endif | |
224 | |
225 | |
226 static int ag_look_ahead(void) { | |
227 if ((PCB).rx < (PCB).fx) { | |
228 return CONVERT_CASE((PCB).lab[(PCB).rx++]); | |
229 } | |
230 GET_INPUT; | |
231 (PCB).fx++; | |
232 return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code); | |
233 } | |
234 | |
235 static void ag_get_key_word(int ag_k) { | |
236 int save_index = (PCB).rx; | |
237 const unsigned char *sp; | |
238 int ag_ch; | |
239 while (1) { | |
240 switch (ag_key_act[ag_k]) { | |
241 case ag_cf_end_key: | |
242 sp = ag_key_ends + ag_key_jmp[ag_k]; | |
243 do { | |
244 if ((ag_ch = *sp++) == 0) { | |
245 int ag_k1 = ag_key_parm[ag_k]; | |
246 int ag_k2 = ag_key_pt[ag_k1]; | |
247 if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail; | |
248 (PCB).rx--; | |
249 (PCB).token_number = (ffcm_token_type) ag_key_pt[ag_k1 + 1]; | |
250 return; | |
251 } | |
252 } while (ag_look_ahead() == ag_ch); | |
253 goto ag_fail; | |
254 case ag_end_key: | |
255 sp = ag_key_ends + ag_key_jmp[ag_k]; | |
256 do { | |
257 if ((ag_ch = *sp++) == 0) { | |
258 (PCB).token_number = (ffcm_token_type) ag_key_parm[ag_k]; | |
259 return; | |
260 } | |
261 } while (ag_look_ahead() == ag_ch); | |
262 case ag_no_match_key: | |
263 ag_fail: | |
264 (PCB).rx = save_index; | |
265 return; | |
266 case ag_cf_set_key: { | |
267 int ag_k1 = ag_key_parm[ag_k]; | |
268 int ag_k2 = ag_key_pt[ag_k1]; | |
269 ag_k = ag_key_jmp[ag_k]; | |
270 if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break; | |
271 save_index = --(PCB).rx; | |
272 (PCB).token_number = (ffcm_token_type) ag_key_pt[ag_k1+1]; | |
273 break; | |
274 } | |
275 case ag_set_key: | |
276 save_index = (PCB).rx; | |
277 (PCB).token_number = (ffcm_token_type) ag_key_parm[ag_k]; | |
278 case ag_jmp_key: | |
279 ag_k = ag_key_jmp[ag_k]; | |
280 ag_ch = ag_look_ahead(); | |
281 break; | |
282 case ag_accept_key: | |
283 (PCB).token_number = (ffcm_token_type) ag_key_parm[ag_k]; | |
284 return; | |
285 case ag_cf_accept_key: { | |
286 int ag_k1 = ag_key_parm[ag_k]; | |
287 int ag_k2 = ag_key_pt[ag_k1]; | |
288 if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index; | |
289 else { | |
290 (PCB).rx--; | |
291 (PCB).token_number = (ffcm_token_type) ag_key_pt[ag_k1+1]; | |
292 } | |
293 return; | |
294 } | |
295 default: | |
296 /* not reachable; here to suppress compiler warnings */ | |
297 goto ag_fail; | |
298 } | |
299 if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
300 if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) { | |
301 (PCB).rx = save_index; | |
302 return; | |
303 } | |
304 } | |
305 } | |
306 | |
307 | |
308 #ifndef AG_NEWLINE | |
309 #define AG_NEWLINE 10 | |
310 #endif | |
311 | |
312 #ifndef AG_RETURN | |
313 #define AG_RETURN 13 | |
314 #endif | |
315 | |
316 #ifndef AG_FORMFEED | |
317 #define AG_FORMFEED 12 | |
318 #endif | |
319 | |
320 #ifndef AG_TABCHAR | |
321 #define AG_TABCHAR 9 | |
322 #endif | |
323 | |
324 static void ag_track(void) { | |
325 int ag_k = 0; | |
326 while (ag_k < (PCB).rx) { | |
327 int ag_ch = (PCB).lab[ag_k++]; | |
328 switch (ag_ch) { | |
329 case AG_NEWLINE: | |
330 (PCB).column = 1, (PCB).line++; | |
331 case AG_RETURN: | |
332 case AG_FORMFEED: | |
333 break; | |
334 case AG_TABCHAR: | |
335 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
336 break; | |
337 default: | |
338 (PCB).column++; | |
339 } | |
340 } | |
341 ag_k = 0; | |
342 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++]; | |
343 (PCB).fx = ag_k; | |
344 (PCB).rx = 0; | |
345 } | |
346 | |
347 | |
348 static void ag_prot(void) { | |
349 int ag_k; | |
350 ag_k = 128 - ++(PCB).btsx; | |
351 if (ag_k <= (PCB).ssx) { | |
352 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
353 PARSER_STACK_OVERFLOW; | |
354 return; | |
355 } | |
356 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
357 (PCB).bts[ag_k] = (PCB).ssx; | |
358 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
359 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
360 } | |
361 | |
362 static void ag_undo(void) { | |
363 if ((PCB).drt == -1) return; | |
364 while ((PCB).btsx) { | |
365 int ag_k = 128 - (PCB).btsx; | |
366 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
367 (PCB).ssx = (PCB).bts[ag_k]; | |
368 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
369 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
370 } | |
371 (PCB).token_number = (ffcm_token_type) (PCB).drt; | |
372 (PCB).ssx = (PCB).dssx; | |
373 (PCB).sn = (PCB).dsn; | |
374 (PCB).drt = -1; | |
375 } | |
376 | |
377 | |
378 static const unsigned char ag_tstt[] = { | |
379 43,25,24,9,0,1,40,41, | |
380 54,52,51,50,48,47,46,45,44,42,39,32,29,24,0,27,28, | |
381 43,42,25,24,9,0, | |
382 43,42,25,24,9,0, | |
383 43,42,25,24,9,0,1, | |
384 43,9,0,3,4,6,7,8, | |
385 54,52,51,50,48,47,46,45,44,42,39,32,29,24,0, | |
386 54,52,51,50,48,47,46,45,44,42,39,32,29,24,0, | |
387 29,0, | |
388 43,42,25,24,9,0, | |
389 42,25,24,0,1,40,41, | |
390 42,0,5, | |
391 43,9,0, | |
392 43,9,0,4,6, | |
393 9,0, | |
394 54,52,51,50,48,47,46,45,44,42,39,32,29,24,0, | |
395 43,42,25,24,9,0, | |
396 42,0, | |
397 43,25,24,9,0,1,40,41, | |
398 43,9,0, | |
399 43,9,0, | |
400 43,9,0, | |
401 | |
402 }; | |
403 | |
404 | |
405 static unsigned const char ag_astt[150] = { | |
406 5,1,1,5,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,7,1,1,5,5,5,5,5,7,5,5,5,5,5,7, | |
407 5,5,1,1,5,7,1,1,5,7,0,1,1,1,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,7,1,1,1,1,1,1,1, | |
408 1,1,1,1,1,5,1,7,1,7,5,5,5,5,5,7,5,1,1,7,1,1,1,1,7,1,5,5,7,1,5,7,1,1,3,7,5, | |
409 5,5,5,5,5,5,5,5,5,5,5,5,5,7,5,5,5,5,5,7,5,7,5,1,1,5,7,1,1,1,5,5,7,5,5,7,5, | |
410 5,7 | |
411 }; | |
412 | |
413 | |
414 static const unsigned char ag_pstt[] = { | |
415 56,1,2,56,0,3,4,5, | |
416 6,6,6,6,6,6,6,6,6,6,6,6,24,6,1,7,8, | |
417 21,21,21,21,21,2, | |
418 54,54,54,54,54,3, | |
419 57,57,1,2,57,4,9, | |
420 10,4,5,0,11,12,13,14, | |
421 22,22,22,22,22,22,22,22,22,22,22,22,22,22,6, | |
422 15,15,15,15,15,15,15,15,15,15,15,15,25,15,7, | |
423 16,8, | |
424 55,55,55,55,55,9, | |
425 56,1,2,10,3,4,17, | |
426 18,11,19, | |
427 2,2,12, | |
428 10,5,13,11,20, | |
429 6,14, | |
430 23,23,23,23,23,23,23,23,23,23,23,23,23,23,15, | |
431 26,26,26,26,26,16, | |
432 59,17, | |
433 56,1,2,56,18,3,4,21, | |
434 1,1,19, | |
435 3,3,20, | |
436 58,58,21, | |
437 | |
438 }; | |
439 | |
440 | |
441 static const unsigned char ag_sbt[] = { | |
442 0, 8, 25, 31, 37, 44, 52, 67, 82, 84, 90, 97, 100, 103, | |
443 108, 110, 125, 131, 133, 141, 144, 147, 150 | |
444 }; | |
445 | |
446 | |
447 static const unsigned char ag_sbe[] = { | |
448 4, 22, 30, 36, 42, 46, 66, 81, 83, 89, 93, 98, 102, 105, | |
449 109, 124, 130, 132, 137, 143, 146, 149, 150 | |
450 }; | |
451 | |
452 | |
453 static const unsigned char ag_fl[] = { | |
454 2,2,1,2,0,1,2,1,3,1,1,3,3,1,3,3,1,1,3,2,0,1,1,2,0,1,3,1,3,0,1,2,2,1,2, | |
455 1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,0,1,2,2,2,2,2,2,2,2,2,2,2,2, | |
456 2 | |
457 }; | |
458 | |
459 static const unsigned char ag_ptt[] = { | |
460 0, 6, 7, 7, 8, 8, 3, 10, 10, 10, 11, 11, 11, 15, 15, 15, 18, 18, | |
461 18, 18, 21, 1, 27, 27, 28, 28, 1, 12, 49, 34, 34, 49, 49, 31, 31, 33, | |
462 33, 12, 12, 35, 37, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, | |
463 40, 40, 41, 41, 5, 4, 13, 16, 17, 19, 20, 2, 23, 22, 30, 36, 38 | |
464 }; | |
465 | |
466 | |
467 static void ag_ra(void) | |
468 { | |
469 switch(ag_rpx[(PCB).ag_ap]) { | |
470 case 1: ag_rp_1(V(0,(double *))); break; | |
471 case 2: ag_rp_2(V(0,(int *)), V(2,(double *))); break; | |
472 case 3: V(0,(double *)) = ag_rp_3(V(0,(double *)), V(2,(double *))); break; | |
473 case 4: V(0,(double *)) = ag_rp_4(V(0,(double *)), V(2,(double *))); break; | |
474 case 5: V(0,(double *)) = ag_rp_5(V(0,(double *)), V(2,(double *))); break; | |
475 case 6: V(0,(double *)) = ag_rp_6(V(0,(double *)), V(2,(double *))); break; | |
476 case 7: V(0,(double *)) = ag_rp_7(V(0,(double *))); break; | |
477 case 8: V(0,(double *)) = ag_rp_8(V(1,(double *))); break; | |
478 case 9: V(0,(double *)) = ag_rp_9(V(1,(double *))); break; | |
479 case 10: V(0,(int *)) = ag_rp_10(V(0,(int *))); break; | |
480 case 11: V(0,(double *)) = ag_rp_11(V(0,(double *)), V(2,(double *))); break; | |
481 case 12: V(0,(double *)) = ag_rp_12(V(1,(double *))); break; | |
482 case 13: V(0,(double *)) = ag_rp_13(V(0,(int *))); break; | |
483 case 14: V(0,(double *)) = ag_rp_14(V(0,(double *)), V(1,(int *))); break; | |
484 case 15: V(0,(double *)) = ag_rp_15(V(0,(int *))); break; | |
485 case 16: V(0,(double *)) = ag_rp_16(V(0,(int *)), V(1,(double *))); break; | |
486 case 17: V(0,(int *)) = ag_rp_17(V(0,(int *))); break; | |
487 case 18: V(0,(int *)) = ag_rp_18(V(1,(int *))); break; | |
488 } | |
489 } | |
490 | |
491 #define TOKEN_NAMES ffcm_token_names | |
492 const char *const ffcm_token_names[55] = { | |
493 "calculator", | |
494 "white space", | |
495 "real", | |
496 "calculator", | |
497 "statement", | |
498 "'\\n'", | |
499 "", | |
500 "", | |
501 "", | |
502 "eof", | |
503 "calculation", | |
504 "expression", | |
505 "name", | |
506 "'='", | |
507 "error", | |
508 "term", | |
509 "'+'", | |
510 "'-'", | |
511 "factor", | |
512 "'*'", | |
513 "'/'", | |
514 "identifier", | |
515 "'('", | |
516 "')'", | |
517 "", | |
518 "\"/*\"", | |
519 "", | |
520 "", | |
521 "", | |
522 "\"*/\"", | |
523 "", | |
524 "integer part", | |
525 "'.'", | |
526 "fraction part", | |
527 "", | |
528 "digit", | |
529 "letter", | |
530 "", | |
531 "", | |
532 "", | |
533 "", | |
534 "", | |
535 "'\\n'", | |
536 "statement", | |
537 "'='", | |
538 "'+'", | |
539 "'-'", | |
540 "'*'", | |
541 "'/'", | |
542 "real", | |
543 "')'", | |
544 "'('", | |
545 "", | |
546 "letter", | |
547 "", | |
548 | |
549 }; | |
550 | |
551 #ifndef MISSING_FORMAT | |
552 #define MISSING_FORMAT "Missing %s" | |
553 #endif | |
554 #ifndef UNEXPECTED_FORMAT | |
555 #define UNEXPECTED_FORMAT "Unexpected %s" | |
556 #endif | |
557 #ifndef UNNAMED_TOKEN | |
558 #define UNNAMED_TOKEN "input" | |
559 #endif | |
560 | |
561 | |
562 static void ag_diagnose(void) { | |
563 int ag_snd = (PCB).sn; | |
564 int ag_k = ag_sbt[ag_snd]; | |
565 | |
566 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
567 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
568 } | |
569 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
570 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
571 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
572 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
573 } | |
574 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
575 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
576 } | |
577 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') { | |
578 char buf[20]; | |
579 sprintf(buf, "\'%c\'", (char) (*(PCB).lab)); | |
580 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
581 } | |
582 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
583 (PCB).error_message = (PCB).ag_msg; | |
584 | |
585 | |
586 } | |
587 static int ag_action_1_r_proc(void); | |
588 static int ag_action_2_r_proc(void); | |
589 static int ag_action_3_r_proc(void); | |
590 static int ag_action_4_r_proc(void); | |
591 static int ag_action_1_s_proc(void); | |
592 static int ag_action_3_s_proc(void); | |
593 static int ag_action_1_proc(void); | |
594 static int ag_action_2_proc(void); | |
595 static int ag_action_3_proc(void); | |
596 static int ag_action_4_proc(void); | |
597 static int ag_action_5_proc(void); | |
598 static int ag_action_6_proc(void); | |
599 static int ag_action_7_proc(void); | |
600 static int ag_action_8_proc(void); | |
601 static int ag_action_9_proc(void); | |
602 static int ag_action_10_proc(void); | |
603 static int ag_action_11_proc(void); | |
604 static int ag_action_8_proc(void); | |
605 | |
606 | |
607 static int (*const ag_r_procs_scan[])(void) = { | |
608 ag_action_1_r_proc, | |
609 ag_action_2_r_proc, | |
610 ag_action_3_r_proc, | |
611 ag_action_4_r_proc | |
612 }; | |
613 | |
614 static int (*const ag_s_procs_scan[])(void) = { | |
615 ag_action_1_s_proc, | |
616 ag_action_2_r_proc, | |
617 ag_action_3_s_proc, | |
618 ag_action_4_r_proc | |
619 }; | |
620 | |
621 static int (*const ag_gt_procs_scan[])(void) = { | |
622 ag_action_1_proc, | |
623 ag_action_2_proc, | |
624 ag_action_3_proc, | |
625 ag_action_4_proc, | |
626 ag_action_5_proc, | |
627 ag_action_6_proc, | |
628 ag_action_7_proc, | |
629 ag_action_8_proc, | |
630 ag_action_9_proc, | |
631 ag_action_10_proc, | |
632 ag_action_11_proc, | |
633 ag_action_8_proc | |
634 }; | |
635 | |
636 | |
637 static int ag_action_1_er_proc(void); | |
638 static int ag_action_2_er_proc(void); | |
639 static int ag_action_3_er_proc(void); | |
640 static int ag_action_4_er_proc(void); | |
641 | |
642 static int (*const ag_er_procs_scan[])(void) = { | |
643 ag_action_1_er_proc, | |
644 ag_action_2_er_proc, | |
645 ag_action_3_er_proc, | |
646 ag_action_4_er_proc | |
647 }; | |
648 | |
649 | |
650 static void ag_error_resynch(void) { | |
651 int ag_k; | |
652 int ag_ssx = (PCB).ssx; | |
653 | |
654 ag_diagnose(); | |
655 SYNTAX_ERROR; | |
656 if ((PCB).exit_flag != AG_RUNNING_CODE) return; | |
657 while (1) { | |
658 ag_k = ag_sbt[(PCB).sn]; | |
659 while (ag_tstt[ag_k] != 14 && ag_tstt[ag_k]) ag_k++; | |
660 if (ag_tstt[ag_k] || (PCB).ssx == 0) break; | |
661 (PCB).sn = (PCB).ss[--(PCB).ssx]; | |
662 } | |
663 if (ag_tstt[ag_k] == 0) { | |
664 (PCB).sn = PCB.ss[(PCB).ssx = ag_ssx]; | |
665 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
666 return; | |
667 } | |
668 ag_k = ag_sbt[(PCB).sn]; | |
669 while (ag_tstt[ag_k] != 14 && ag_tstt[ag_k]) ag_k++; | |
670 (PCB).ag_ap = ag_pstt[ag_k]; | |
671 (ag_er_procs_scan[ag_astt[ag_k]])(); | |
672 while (1) { | |
673 ag_k = ag_sbt[(PCB).sn]; | |
674 while (ag_tstt[ag_k] != (unsigned char) (PCB).token_number && ag_tstt[ag_k]) | |
675 ag_k++; | |
676 if (ag_tstt[ag_k] && ag_astt[ag_k] != ag_action_10) break; | |
677 if ((PCB).token_number == 9) | |
678 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;} | |
679 {(PCB).rx = 1; ag_track();} | |
680 if ((PCB).rx < (PCB).fx) { | |
681 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
682 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code);} | |
683 else { | |
684 GET_INPUT; | |
685 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
686 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code); | |
687 (PCB).rx++; | |
688 } | |
689 if (ag_key_index[(PCB).sn]) { | |
690 unsigned ag_k = ag_key_index[(PCB).sn]; | |
691 int ag_ch = CONVERT_CASE((PCB).input_code); | |
692 if (ag_ch < 255) { | |
693 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
694 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
695 } | |
696 } | |
697 } | |
698 (PCB).rx = 0; | |
699 } | |
700 | |
701 | |
702 static int ag_action_10_proc(void) { | |
703 int ag_t = (PCB).token_number; | |
704 (PCB).btsx = 0, (PCB).drt = -1; | |
705 do { | |
706 ag_track(); | |
707 if ((PCB).rx < (PCB).fx) { | |
708 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
709 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code);} | |
710 else { | |
711 GET_INPUT; | |
712 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
713 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code); | |
714 (PCB).rx++; | |
715 } | |
716 if (ag_key_index[(PCB).sn]) { | |
717 unsigned ag_k = ag_key_index[(PCB).sn]; | |
718 int ag_ch = CONVERT_CASE((PCB).input_code); | |
719 if (ag_ch < 255) { | |
720 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
721 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
722 } | |
723 } | |
724 } while ((PCB).token_number == (ffcm_token_type) ag_t); | |
725 (PCB).rx = 0; | |
726 return 1; | |
727 } | |
728 | |
729 static int ag_action_11_proc(void) { | |
730 int ag_t = (PCB).token_number; | |
731 | |
732 (PCB).btsx = 0, (PCB).drt = -1; | |
733 do { | |
734 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
735 (PCB).ssx--; | |
736 ag_track(); | |
737 ag_ra(); | |
738 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
739 (PCB).ssx++; | |
740 if ((PCB).rx < (PCB).fx) { | |
741 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
742 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code);} | |
743 else { | |
744 GET_INPUT; | |
745 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
746 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code); | |
747 (PCB).rx++; | |
748 } | |
749 if (ag_key_index[(PCB).sn]) { | |
750 unsigned ag_k = ag_key_index[(PCB).sn]; | |
751 int ag_ch = CONVERT_CASE((PCB).input_code); | |
752 if (ag_ch < 255) { | |
753 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
754 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
755 } | |
756 } | |
757 } | |
758 while ((PCB).token_number == (ffcm_token_type) ag_t); | |
759 (PCB).rx = 0; | |
760 return 1; | |
761 } | |
762 | |
763 static int ag_action_3_r_proc(void) { | |
764 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
765 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
766 (PCB).btsx = 0, (PCB).drt = -1; | |
767 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
768 ag_ra(); | |
769 return (PCB).exit_flag == AG_RUNNING_CODE; | |
770 } | |
771 | |
772 static int ag_action_3_s_proc(void) { | |
773 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
774 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
775 (PCB).btsx = 0, (PCB).drt = -1; | |
776 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
777 ag_ra(); | |
778 return (PCB).exit_flag == AG_RUNNING_CODE; | |
779 } | |
780 | |
781 static int ag_action_4_r_proc(void) { | |
782 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
783 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
784 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
785 return 1; | |
786 } | |
787 | |
788 static int ag_action_2_proc(void) { | |
789 (PCB).btsx = 0, (PCB).drt = -1; | |
790 if ((PCB).ssx >= 128) { | |
791 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
792 PARSER_STACK_OVERFLOW; | |
793 } | |
794 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
795 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
796 (PCB).ssx++; | |
797 (PCB).sn = (PCB).ag_ap; | |
798 ag_track(); | |
799 return 0; | |
800 } | |
801 | |
802 static int ag_action_9_proc(void) { | |
803 if ((PCB).drt == -1) { | |
804 (PCB).drt=(PCB).token_number; | |
805 (PCB).dssx=(PCB).ssx; | |
806 (PCB).dsn=(PCB).sn; | |
807 } | |
808 ag_prot(); | |
809 (PCB).vs[(PCB).ssx] = ag_null_value; | |
810 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
811 (PCB).ssx++; | |
812 (PCB).sn = (PCB).ag_ap; | |
813 (PCB).rx = 0; | |
814 return (PCB).exit_flag == AG_RUNNING_CODE; | |
815 } | |
816 | |
817 static int ag_action_2_r_proc(void) { | |
818 (PCB).ssx++; | |
819 (PCB).sn = (PCB).ag_ap; | |
820 return 0; | |
821 } | |
822 | |
823 static int ag_action_7_proc(void) { | |
824 --(PCB).ssx; | |
825 (PCB).rx = 0; | |
826 (PCB).exit_flag = AG_SUCCESS_CODE; | |
827 return 0; | |
828 } | |
829 | |
830 static int ag_action_1_proc(void) { | |
831 ag_track(); | |
832 (PCB).exit_flag = AG_SUCCESS_CODE; | |
833 return 0; | |
834 } | |
835 | |
836 static int ag_action_1_r_proc(void) { | |
837 (PCB).exit_flag = AG_SUCCESS_CODE; | |
838 return 0; | |
839 } | |
840 | |
841 static int ag_action_1_s_proc(void) { | |
842 (PCB).exit_flag = AG_SUCCESS_CODE; | |
843 return 0; | |
844 } | |
845 | |
846 static int ag_action_4_proc(void) { | |
847 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
848 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
849 (PCB).btsx = 0, (PCB).drt = -1; | |
850 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
851 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
852 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
853 ag_track(); | |
854 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
855 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
856 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
857 do { | |
858 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
859 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
860 else ag_t2 = ag_tx; | |
861 } while (ag_t1 < ag_t2); | |
862 (PCB).ag_ap = ag_pstt[ag_t1]; | |
863 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
864 } | |
865 return 0; | |
866 } | |
867 | |
868 static int ag_action_3_proc(void) { | |
869 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
870 (PCB).btsx = 0, (PCB).drt = -1; | |
871 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
872 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
873 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
874 ag_track(); | |
875 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
876 ag_ra(); | |
877 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
878 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
879 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
880 do { | |
881 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
882 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
883 else ag_t2 = ag_tx; | |
884 } while (ag_t1 < ag_t2); | |
885 (PCB).ag_ap = ag_pstt[ag_t1]; | |
886 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
887 } | |
888 return 0; | |
889 } | |
890 | |
891 static int ag_action_8_proc(void) { | |
892 int ag_k = ag_sbt[(PCB).sn]; | |
893 while (ag_tstt[ag_k] != 14 && ag_tstt[ag_k]) ag_k++; | |
894 if (ag_tstt[ag_k] == 0) ag_undo(); | |
895 (PCB).rx = 0; | |
896 ag_error_resynch(); | |
897 return (PCB).exit_flag == AG_RUNNING_CODE; | |
898 } | |
899 | |
900 static int ag_action_5_proc(void) { | |
901 int ag_sd = ag_fl[(PCB).ag_ap]; | |
902 (PCB).btsx = 0, (PCB).drt = -1; | |
903 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
904 else { | |
905 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
906 } | |
907 (PCB).rx = 0; | |
908 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
909 ag_ra(); | |
910 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
911 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
912 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
913 do { | |
914 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
915 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
916 else ag_t2 = ag_tx; | |
917 } while (ag_t1 < ag_t2); | |
918 (PCB).ag_ap = ag_pstt[ag_t1]; | |
919 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
920 } | |
921 return (PCB).exit_flag == AG_RUNNING_CODE; | |
922 } | |
923 | |
924 static int ag_action_6_proc(void) { | |
925 int ag_sd = ag_fl[(PCB).ag_ap]; | |
926 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
927 if ((PCB).drt == -1) { | |
928 (PCB).drt=(PCB).token_number; | |
929 (PCB).dssx=(PCB).ssx; | |
930 (PCB).dsn=(PCB).sn; | |
931 } | |
932 if (ag_sd) { | |
933 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
934 } | |
935 else { | |
936 ag_prot(); | |
937 (PCB).vs[(PCB).ssx] = ag_null_value; | |
938 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
939 } | |
940 (PCB).rx = 0; | |
941 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
942 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
943 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
944 do { | |
945 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
946 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
947 else ag_t2 = ag_tx; | |
948 } while (ag_t1 < ag_t2); | |
949 (PCB).ag_ap = ag_pstt[ag_t1]; | |
950 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
951 } | |
952 return (PCB).exit_flag == AG_RUNNING_CODE; | |
953 } | |
954 | |
955 | |
956 static int ag_action_2_er_proc(void) { | |
957 (PCB).btsx = 0, (PCB).drt = -1; | |
958 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
959 (PCB).ssx++; | |
960 (PCB).sn = (PCB).ag_ap; | |
961 return 0; | |
962 } | |
963 | |
964 static int ag_action_1_er_proc(void) { | |
965 (PCB).btsx = 0, (PCB).drt = -1; | |
966 (PCB).exit_flag = AG_SUCCESS_CODE; | |
967 return 0; | |
968 } | |
969 | |
970 static int ag_action_4_er_proc(void) { | |
971 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
972 (PCB).btsx = 0, (PCB).drt = -1; | |
973 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
974 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
975 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
976 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
977 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
978 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
979 do { | |
980 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
981 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
982 else ag_t2 = ag_tx; | |
983 } while (ag_t1 < ag_t2); | |
984 (PCB).ag_ap = ag_pstt[ag_t1]; | |
985 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
986 } | |
987 return 0; | |
988 } | |
989 | |
990 static int ag_action_3_er_proc(void) { | |
991 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
992 (PCB).btsx = 0, (PCB).drt = -1; | |
993 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
994 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
995 (PCB).reduction_token = (ffcm_token_type) ag_ptt[(PCB).ag_ap]; | |
996 ag_ra(); | |
997 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
998 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
999 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1000 do { | |
1001 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1002 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1003 else ag_t2 = ag_tx; | |
1004 } while (ag_t1 < ag_t2); | |
1005 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1006 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
1007 } | |
1008 return 0; | |
1009 } | |
1010 | |
1011 | |
1012 void init_ffcm(void) { | |
1013 (PCB).rx = (PCB).fx = 0; | |
1014 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
1015 (PCB).exit_flag = AG_RUNNING_CODE; | |
1016 (PCB).line = FIRST_LINE; | |
1017 (PCB).column = FIRST_COLUMN; | |
1018 (PCB).btsx = 0, (PCB).drt = -1; | |
1019 } | |
1020 | |
1021 void ffcm(void) { | |
1022 init_ffcm(); | |
1023 (PCB).exit_flag = AG_RUNNING_CODE; | |
1024 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1025 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
1026 if (ag_tstt[ag_t1]) { | |
1027 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
1028 if ((PCB).rx < (PCB).fx) { | |
1029 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
1030 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code);} | |
1031 else { | |
1032 GET_INPUT; | |
1033 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
1034 (PCB).token_number = (ffcm_token_type) AG_TCV((PCB).input_code); | |
1035 (PCB).rx++; | |
1036 } | |
1037 if (ag_key_index[(PCB).sn]) { | |
1038 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1039 int ag_ch = CONVERT_CASE((PCB).input_code); | |
1040 if (ag_ch < 255) { | |
1041 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1042 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1043 } | |
1044 } | |
1045 do { | |
1046 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1047 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
1048 ag_t1 = ag_tx + 1; | |
1049 else ag_t2 = ag_tx; | |
1050 } while (ag_t1 < ag_t2); | |
1051 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
1052 ag_t1 = ag_sbe[(PCB).sn]; | |
1053 } | |
1054 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1055 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
1056 } | |
1057 } | |
1058 | |
1059 |