comparison tests/agcl/ffcalc/good/ffc-wa.cpp @ 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 /*
2 FOUR FUNCTION CALCULATOR: FFCALC.SYN
3 */
4 #include "Number.h"
5
6 int Number::nCreated = 0;
7 char Number::buf[100];
8
9
10 /*
11 * AnaGram, A System for Syntax Directed Programming
12 * File generated by: ...
13 *
14 * AnaGram Parsing Engine
15 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
16 *
17 * This software is provided 'as-is', without any express or implied
18 * warranty. In no event will the authors be held liable for any damages
19 * arising from the use of this software.
20 *
21 * Permission is granted to anyone to use this software for any purpose,
22 * including commercial applications, and to alter it and redistribute it
23 * freely, subject to the following restrictions:
24 *
25 * 1. The origin of this software must not be misrepresented; you must not
26 * claim that you wrote the original software. If you use this software
27 * in a product, an acknowledgment in the product documentation would be
28 * appreciated but is not required.
29 * 2. Altered source versions must be plainly marked as such, and must not be
30 * misrepresented as being the original software.
31 * 3. This notice may not be removed or altered from any source distribution.
32 */
33
34 #ifndef FFC-WA_H
35 #include "ffc-wa.h"
36 #endif
37
38 #ifndef FFC-WA_H
39 #error Mismatched header file
40 #endif
41
42 #include <ctype.h>
43 #include <stdio.h>
44
45 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
46 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
47 #define CONTEXT ((PCB).cs[(PCB).ssx])
48
49
50
51 ffc-wa_pcb_type ffc-wa_pcb;
52 #define PCB ffc-wa_pcb
53 static void ag_delete_wrappers(void);
54 #ifndef DELETE_WRAPPERS
55 #define DELETE_WRAPPERS ag_delete_wrappers()
56 #endif
57
58 #line - "ffc-wa.syn"
59 /* -- EMBEDDED C ---------------------------------- */
60
61 #define SYNTAX_ERROR printf("%s, line %d, column %d\n", \
62 (PCB).error_message, (PCB).line, (PCB).column), fflush(stdout)
63
64 Number value[64]; /* registers */
65 int main(void) {
66 ffcalcr();
67 return 0;
68 }
69 #line - "ffc-wa.cpp"
70
71 #ifndef CONVERT_CASE
72 #define CONVERT_CASE(c) (c)
73 #endif
74 #ifndef TAB_SPACING
75 #define TAB_SPACING 8
76 #endif
77
78 static void ag_rp_1(Number &x) {
79 #line - "ffc-wa.syn"
80 printf("%s\n", x.asString()),fflush(stdout);
81 #line - "ffc-wa.cpp"
82 }
83
84 static void ag_rp_2(int n, Number &x) {
85 #line - "ffc-wa.syn"
86 printf("%c = %s\n",n+'A', fflush(stdout), (value[n]=x).asString());
87 #line - "ffc-wa.cpp"
88 }
89
90 static Number ag_rp_3(Number &x, Number &t) {
91 #line - "ffc-wa.syn"
92 printf("x = %s\n", x.asString());
93 printf("t = %s\n", t.asString());
94 fflush(stdout);
95 x+=t;
96 printf("x = %s\n", x.asString());
97 fflush(stdout);
98 return x;
99
100 #line - "ffc-wa.cpp"
101 }
102
103 static Number ag_rp_4(Number &x, Number &t) {
104 #line - "ffc-wa.syn"
105 return x-=t;
106 #line - "ffc-wa.cpp"
107 }
108
109 static Number ag_rp_5(Number &t, Number &f) {
110 #line - "ffc-wa.syn"
111 return t*=f;
112 #line - "ffc-wa.cpp"
113 }
114
115 static Number ag_rp_6(Number &t, Number &f) {
116 #line - "ffc-wa.syn"
117 return t/=f;
118 #line - "ffc-wa.cpp"
119 }
120
121 static Number ag_rp_7(int n) {
122 #line - "ffc-wa.syn"
123 return value[n];
124 #line - "ffc-wa.cpp"
125 }
126
127 static Number ag_rp_8(double x) {
128 #line - "ffc-wa.syn"
129 return Number(x);
130 #line - "ffc-wa.cpp"
131 }
132
133 static Number ag_rp_9(Number &x) {
134 #line - "ffc-wa.syn"
135 return x;
136 #line - "ffc-wa.cpp"
137 }
138
139 static Number ag_rp_10(Number &f) {
140 #line - "ffc-wa.syn"
141 return -f;
142 #line - "ffc-wa.cpp"
143 }
144
145 static int ag_rp_11(int c) {
146 #line - "ffc-wa.syn"
147 return c-'A';
148 #line - "ffc-wa.cpp"
149 }
150
151 static double ag_rp_12(double i, double f) {
152 #line - "ffc-wa.syn"
153 return i+f;
154 #line - "ffc-wa.cpp"
155 }
156
157 static double ag_rp_13(double f) {
158 #line - "ffc-wa.syn"
159 return f;
160 #line - "ffc-wa.cpp"
161 }
162
163 static double ag_rp_14(int d) {
164 #line - "ffc-wa.syn"
165 return d-'0';
166 #line - "ffc-wa.cpp"
167 }
168
169 static double ag_rp_15(double x, int d) {
170 #line - "ffc-wa.syn"
171 return 10*x + d-'0';
172 #line - "ffc-wa.cpp"
173 }
174
175 static double ag_rp_16(int d) {
176 #line - "ffc-wa.syn"
177 return (d-'0')/10.;
178 #line - "ffc-wa.cpp"
179 }
180
181 static double ag_rp_17(int d, double f) {
182 #line - "ffc-wa.syn"
183 return (d-'0' + f)/10.;
184 #line - "ffc-wa.cpp"
185 }
186
187
188 #define READ_COUNTS
189 #define WRITE_COUNTS
190 #undef V
191 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
192 #undef VS
193 #define VS(i) (PCB).vs[(PCB).ssx + i]
194
195 #ifndef GET_CONTEXT
196 #define GET_CONTEXT CONTEXT = (PCB).input_context
197 #endif
198
199 typedef enum {
200 ag_action_1,
201 ag_action_2,
202 ag_action_3,
203 ag_action_4,
204 ag_action_5,
205 ag_action_6,
206 ag_action_7,
207 ag_action_8,
208 ag_action_9,
209 ag_action_10,
210 ag_action_11,
211 ag_action_12
212 } ag_parser_action;
213
214
215 #ifndef NULL_VALUE_INITIALIZER
216 #define NULL_VALUE_INITIALIZER = { 0 }
217 #endif
218
219
220 static const char ag_wdf[] = {
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 0, 0, 4, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4
223 };
224
225 #undef VW
226 #define VW(i,t) *(t) (&(PCB).vs[(PCB).ssx + (i)])
227 #undef VNO
228 #define VNO new(&(PCB).vs[(PCB).ssx])
229 #undef VRO
230 #define VRO(to,v) ag_replace_object((to) &(PCB).vs[(PCB).ssx], v)
231 #undef VWD
232 #define VWD(i,t) ag_delete_object((t) &(PCB).vs[(PCB).ssx + (i)]);
233 #undef VDO
234 #define VDO(to, v) ag_delete_object((to) &(PCB).vs[(PCB).ssx], v)
235
236 template <class NewObject, class OldObject>
237 static inline void ag_replace_object(AgObjectWrapper<OldObject> *p, const NewObject &o) {
238 delete p;
239 new(p) AgObjectWrapper<NewObject >(o);
240 }
241
242 template <class Object>
243 static inline void ag_delete_object(AgObjectWrapper<Object> *p) {
244 delete p;
245 }
246
247 template <class NewObject, class OldObject>
248 static inline const NewObject &ag_delete_object(AgObjectWrapper<OldObject> *p, const NewObject &o) {
249 delete p;
250 return o;
251 }
252
253
254 #undef AG_WRAP_4
255 #define AG_WRAP_4 AgObjectWrapper<Number >
256
257 static void ag_delete_wrappers(void) {
258 if ((PCB).ag_resynch_active) return;
259 (PCB).ag_resynch_active = 1;
260 int sn = (PCB).sn;
261 int sx = (PCB).ssx;
262 while (sx--) {
263 switch (ag_wdf[sn]) {
264 case 4: ag_delete_object((AG_WRAP_4 *) &(PCB).vs[sx]); break;
265 default: break;
266 }
267 sn = (PCB).ss[sx];
268 }
269 }
270
271 static ffc-wa_vs_type const ag_null_value NULL_VALUE_INITIALIZER;
272
273 static const unsigned char ag_rpx[] = {
274 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 4, 0, 5, 6, 7,
275 8, 9, 10, 0, 0, 0, 0, 0, 0, 11, 12, 0, 0, 0, 13, 14, 15, 16,
276 17
277 };
278
279 static const unsigned char ag_key_itt[] = {
280 0
281 };
282
283 static const unsigned short ag_key_pt[] = {
284 0
285 };
286
287 static const unsigned char ag_key_ch[] = {
288 0, 47,255, 42,255
289 };
290
291 static const unsigned char ag_key_act[] = {
292 0,3,4,3,4
293 };
294
295 static const unsigned char ag_key_parm[] = {
296 0, 23, 0, 27, 0
297 };
298
299 static const unsigned char ag_key_jmp[] = {
300 0, 0, 0, 2, 0
301 };
302
303 static const unsigned char ag_key_index[] = {
304 1, 3, 1, 0, 3, 3, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0,
305 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0,
306 0
307 };
308
309 static const unsigned char ag_key_ends[] = {
310 42,0, 47,0,
311 };
312 #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0)
313
314 static const unsigned char ag_tcv[] = {
315 10, 34, 34, 34, 34, 34, 34, 34, 34, 34, 22, 37, 22, 22, 22, 34, 34, 34,
316 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 22, 34, 34,
317 34, 34, 34, 34, 34, 45, 44, 41, 39, 34, 40, 30, 42, 33, 33, 33, 33, 33,
318 33, 33, 33, 33, 33, 34, 34, 34, 38, 34, 34, 34, 46, 46, 46, 46, 46, 46,
319 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
320 46, 46, 34, 34, 34, 34, 34, 34, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
321 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 34, 34,
322 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
323 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
324 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
325 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
326 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
327 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
328 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
329 34, 34, 34, 34, 34
330 };
331
332 #ifndef SYNTAX_ERROR
333 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
334 (PCB).error_message, (PCB).line, (PCB).column)
335 #endif
336
337 #ifndef FIRST_LINE
338 #define FIRST_LINE 1
339 #endif
340
341 #ifndef FIRST_COLUMN
342 #define FIRST_COLUMN 1
343 #endif
344
345 #ifndef PARSER_STACK_OVERFLOW
346 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
347 "\nParser stack overflow, line %d, column %d\n",\
348 (PCB).line, (PCB).column);}
349 #endif
350
351 #ifndef REDUCTION_TOKEN_ERROR
352 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
353 "\nReduction token error, line %d, column %d\n", \
354 (PCB).line, (PCB).column);}
355 #endif
356
357
358 typedef enum
359 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
360 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
361
362 #ifndef GET_INPUT
363 #define GET_INPUT ((PCB).input_code = getchar())
364 #endif
365
366
367 static int ag_look_ahead(void) {
368 if ((PCB).rx < (PCB).fx) {
369 return CONVERT_CASE((PCB).lab[(PCB).rx++]);
370 }
371 GET_INPUT;
372 (PCB).fx++;
373 return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code);
374 }
375
376 static void ag_get_key_word(int ag_k) {
377 int save_index = (PCB).rx;
378 const unsigned char *sp;
379 int ag_ch;
380 while (1) {
381 switch (ag_key_act[ag_k]) {
382 case ag_cf_end_key:
383 sp = ag_key_ends + ag_key_jmp[ag_k];
384 do {
385 if ((ag_ch = *sp++) == 0) {
386 int ag_k1 = ag_key_parm[ag_k];
387 int ag_k2 = ag_key_pt[ag_k1];
388 if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail;
389 (PCB).rx--;
390 (PCB).token_number = (ffc-wa_token_type) ag_key_pt[ag_k1 + 1];
391 return;
392 }
393 } while (ag_look_ahead() == ag_ch);
394 goto ag_fail;
395 case ag_end_key:
396 sp = ag_key_ends + ag_key_jmp[ag_k];
397 do {
398 if ((ag_ch = *sp++) == 0) {
399 (PCB).token_number = (ffc-wa_token_type) ag_key_parm[ag_k];
400 return;
401 }
402 } while (ag_look_ahead() == ag_ch);
403 case ag_no_match_key:
404 ag_fail:
405 (PCB).rx = save_index;
406 return;
407 case ag_cf_set_key: {
408 int ag_k1 = ag_key_parm[ag_k];
409 int ag_k2 = ag_key_pt[ag_k1];
410 ag_k = ag_key_jmp[ag_k];
411 if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break;
412 save_index = --(PCB).rx;
413 (PCB).token_number = (ffc-wa_token_type) ag_key_pt[ag_k1+1];
414 break;
415 }
416 case ag_set_key:
417 save_index = (PCB).rx;
418 (PCB).token_number = (ffc-wa_token_type) ag_key_parm[ag_k];
419 case ag_jmp_key:
420 ag_k = ag_key_jmp[ag_k];
421 ag_ch = ag_look_ahead();
422 break;
423 case ag_accept_key:
424 (PCB).token_number = (ffc-wa_token_type) ag_key_parm[ag_k];
425 return;
426 case ag_cf_accept_key: {
427 int ag_k1 = ag_key_parm[ag_k];
428 int ag_k2 = ag_key_pt[ag_k1];
429 if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index;
430 else {
431 (PCB).rx--;
432 (PCB).token_number = (ffc-wa_token_type) ag_key_pt[ag_k1+1];
433 }
434 return;
435 }
436 default:
437 /* not reachable; here to suppress compiler warnings */
438 goto ag_fail;
439 }
440 if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++;
441 if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) {
442 (PCB).rx = save_index;
443 return;
444 }
445 }
446 }
447
448
449 #ifndef AG_NEWLINE
450 #define AG_NEWLINE 10
451 #endif
452
453 #ifndef AG_RETURN
454 #define AG_RETURN 13
455 #endif
456
457 #ifndef AG_FORMFEED
458 #define AG_FORMFEED 12
459 #endif
460
461 #ifndef AG_TABCHAR
462 #define AG_TABCHAR 9
463 #endif
464
465 static void ag_track(void) {
466 int ag_k = 0;
467 while (ag_k < (PCB).rx) {
468 int ag_ch = (PCB).lab[ag_k++];
469 switch (ag_ch) {
470 case AG_NEWLINE:
471 (PCB).column = 1, (PCB).line++;
472 case AG_RETURN:
473 case AG_FORMFEED:
474 break;
475 case AG_TABCHAR:
476 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
477 break;
478 default:
479 (PCB).column++;
480 }
481 }
482 ag_k = 0;
483 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++];
484 (PCB).fx = ag_k;
485 (PCB).rx = 0;
486 }
487
488
489 static void ag_prot(void) {
490 int ag_k;
491 ag_k = 128 - ++(PCB).btsx;
492 if (ag_k <= (PCB).ssx) {
493 (PCB).exit_flag = AG_STACK_ERROR_CODE;
494 PARSER_STACK_OVERFLOW;
495 return;
496 }
497 (PCB).bts[(PCB).btsx] = (PCB).sn;
498 (PCB).bts[ag_k] = (PCB).ssx;
499 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
500 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
501 }
502
503 static void ag_undo(void) {
504 if ((PCB).drt == -1) return;
505 while ((PCB).btsx) {
506 int ag_k = 128 - (PCB).btsx;
507 (PCB).sn = (PCB).bts[(PCB).btsx--];
508 (PCB).ssx = (PCB).bts[ag_k];
509 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
510 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
511 }
512 (PCB).token_number = (ffc-wa_token_type) (PCB).drt;
513 (PCB).ssx = (PCB).dssx;
514 (PCB).sn = (PCB).dsn;
515 (PCB).drt = -1;
516 }
517
518
519 static const unsigned char ag_tstt[] = {
520 46,45,40,37,33,30,23,22,10,0,1,35,36,
521 46,45,44,42,41,40,39,38,37,34,33,30,27,22,0,25,26,
522 23,22,0,1,
523 46,45,40,37,33,30,10,0,2,3,4,5,7,8,9,11,12,14,16,17,20,28,29,43,
524 46,45,44,42,41,40,39,38,37,34,33,30,22,0,
525 27,0,
526 33,0,31,
527 44,42,41,40,39,37,33,30,23,22,0,32,
528 46,45,40,33,30,23,22,0,1,35,36,
529 46,45,40,33,30,23,22,0,1,35,36,
530 44,42,41,40,39,37,23,22,0,1,35,36,
531 46,45,40,33,30,0,2,12,16,17,20,28,29,43,
532 46,45,40,33,30,0,2,11,12,14,16,17,20,28,29,43,
533 44,42,41,40,39,38,37,23,22,0,1,35,36,
534 42,41,0,18,19,
535 38,0,13,
536 40,39,0,15,16,
537 37,0,6,
538 46,45,40,37,33,30,10,0,2,4,5,7,11,12,14,16,17,20,28,29,43,
539 10,0,
540 33,0,31,
541 33,0,31,
542 44,40,39,0,15,16,21,
543 46,45,40,33,30,23,22,0,1,35,36,
544 46,45,40,33,30,0,2,12,16,17,20,28,29,43,
545 46,45,40,33,30,23,22,0,1,35,36,
546 46,45,40,33,30,0,2,12,16,17,20,28,29,43,
547 46,45,40,33,30,23,22,0,1,35,36,
548 46,45,40,33,30,0,2,11,12,14,16,17,20,28,29,43,
549 46,45,40,33,30,0,2,12,14,16,17,20,28,29,43,
550 46,45,40,33,30,23,22,0,1,35,36,
551 46,45,40,33,30,0,2,12,14,16,17,20,28,29,43,
552 46,45,40,37,33,30,23,22,10,0,1,35,36,
553 44,42,41,40,39,37,23,22,0,1,35,36,
554 40,39,0,15,16,
555 42,41,0,18,19,
556 42,41,0,18,19,
557
558 };
559
560
561 static unsigned const char ag_astt[376] = {
562 8,8,8,8,8,8,1,1,8,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,1,7,1,1,1,9,5,3,1,1,1,
563 8,2,1,8,7,2,0,1,1,1,1,1,1,1,1,1,1,1,2,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,5,3,7,
564 1,7,2,5,5,5,5,5,5,10,1,5,5,7,3,5,5,5,5,5,1,1,7,1,1,3,5,5,5,5,5,1,1,7,1,1,3,
565 5,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,7,2,2,1,2,1,2,1,1,1,1,1,2,1,7,2,1,2,1,1,
566 1,1,2,1,1,5,5,5,5,5,5,5,1,1,7,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,1,7,3,1,1,1,
567 8,2,1,5,7,2,1,1,3,1,1,1,1,1,1,2,1,1,3,7,1,4,2,1,5,2,1,1,1,7,1,1,2,5,5,5,5,
568 5,1,1,7,1,1,3,1,1,1,2,1,7,2,2,1,2,1,2,1,1,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,
569 7,2,2,1,2,1,2,1,1,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,7,2,1,2,1,1,1,1,2,1,1,1,
570 1,1,2,1,7,2,2,1,1,1,1,2,1,1,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,7,2,2,1,1,1,1,
571 2,1,1,5,5,5,5,5,5,1,1,5,7,1,1,3,5,5,5,5,5,5,1,1,7,1,1,3,1,1,4,1,1,1,1,4,1,
572 1,1,1,4,1,1
573 };
574
575
576 static const unsigned char ag_pstt[] = {
577 3,3,3,3,3,3,1,2,3,0,2,2,3,
578 4,4,4,4,4,4,4,4,4,4,4,4,5,4,1,4,5,
579 1,51,53,51,
580 13,9,8,17,33,6,19,3,18,0,17,17,18,18,19,16,15,14,11,14,12,27,7,10,
581 23,23,23,23,23,23,23,23,23,23,23,23,23,25,
582 26,5,
583 20,6,32,
584 29,29,29,29,29,29,34,21,29,29,7,31,
585 52,52,52,52,52,1,2,8,2,2,57,
586 52,52,52,52,52,1,2,9,2,2,62,
587 52,52,52,52,52,52,1,2,10,2,2,60,
588 13,9,8,33,6,11,18,17,11,20,12,27,7,10,
589 13,9,8,33,6,12,18,22,17,14,11,14,12,27,7,10,
590 52,52,52,52,52,52,52,1,2,13,2,2,63,
591 23,25,11,26,24,
592 27,17,28,
593 8,30,9,31,29,
594 32,17,3,
595 13,9,8,17,33,6,7,18,18,17,17,5,16,15,14,11,14,12,27,7,10,
596 8,19,
597 20,35,36,
598 20,30,28,
599 33,8,30,22,31,29,19,
600 52,52,52,52,52,1,2,23,2,2,59,
601 13,9,8,33,6,24,18,17,11,16,12,27,7,10,
602 52,52,52,52,52,1,2,25,2,2,58,
603 13,9,8,33,6,26,18,17,11,15,12,27,7,10,
604 52,52,52,52,52,1,2,27,2,2,55,
605 13,9,8,33,6,28,18,34,17,14,11,14,12,27,7,10,
606 13,9,8,33,6,29,18,17,35,11,35,12,27,7,10,
607 52,52,52,52,52,1,2,30,2,2,56,
608 13,9,8,33,6,31,18,17,36,11,36,12,27,7,10,
609 52,52,52,52,52,52,1,2,52,32,2,2,54,
610 52,52,52,52,52,52,1,2,33,2,2,61,
611 8,30,10,31,29,
612 23,25,13,26,24,
613 23,25,12,26,24,
614
615 };
616
617
618 static const unsigned short ag_sbt[] = {
619 0, 13, 30, 34, 58, 72, 74, 77, 89, 100, 111, 123, 137, 153,
620 166, 171, 174, 179, 182, 203, 205, 208, 211, 218, 229, 243, 254, 268,
621 279, 295, 310, 321, 336, 349, 361, 366, 371, 376
622 };
623
624
625 static const unsigned short ag_sbe[] = {
626 9, 27, 32, 41, 71, 73, 75, 87, 96, 107, 119, 128, 142, 162,
627 168, 172, 176, 180, 189, 204, 206, 209, 214, 225, 234, 250, 259, 275,
628 284, 300, 317, 326, 345, 357, 363, 368, 373, 376
629 };
630
631
632 static const unsigned char ag_fl[] = {
633 2,0,1,2,1,2,0,1,2,1,3,1,3,3,1,3,3,1,1,3,2,1,1,2,0,1,3,1,3,0,1,2,2,1,2,
634 1,2,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
635 };
636
637 static const unsigned char ag_ptt[] = {
638 0, 5, 5, 7, 8, 8, 9, 9, 3, 4, 4, 11, 11, 11, 14, 14, 14, 17,
639 17, 17, 17, 1, 25, 25, 26, 26, 1, 12, 43, 32, 32, 43, 43, 29, 29, 31,
640 31, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 35, 35, 36, 36,
641 6, 13, 15, 16, 18, 19, 2, 21, 20, 28
642 };
643
644
645 static void ag_ra(void)
646 {
647 switch(ag_rpx[(PCB).ag_ap]) {
648 case 1: ag_rp_1(VW(0, AG_WRAP_4 *));
649 VWD(0, AG_WRAP_4 *); break;
650 case 2: ag_rp_2(V(0,(int *)), VW(2, AG_WRAP_4 *));
651 VWD(2, AG_WRAP_4 *); break;
652 case 3: VRO(AG_WRAP_4 *, ag_rp_3(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *)));
653 VWD(2, AG_WRAP_4 *); break;
654 case 4: VRO(AG_WRAP_4 *, ag_rp_4(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *)));
655 VWD(2, AG_WRAP_4 *); break;
656 case 5: VRO(AG_WRAP_4 *, ag_rp_5(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *)));
657 VWD(2, AG_WRAP_4 *); break;
658 case 6: VRO(AG_WRAP_4 *, ag_rp_6(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *)));
659 VWD(2, AG_WRAP_4 *); break;
660 case 7: VNO AG_WRAP_4(ag_rp_7(V(0,(int *)))); break;
661 case 8: VNO AG_WRAP_4(ag_rp_8(V(0,(double *)))); break;
662 case 9: VNO AG_WRAP_4(ag_rp_9(VW(1, AG_WRAP_4 *)));
663 VWD(1, AG_WRAP_4 *); break;
664 case 10: VNO AG_WRAP_4(ag_rp_10(VW(1, AG_WRAP_4 *)));
665 VWD(1, AG_WRAP_4 *); break;
666 case 11: V(0,(int *)) = ag_rp_11(V(0,(int *))); break;
667 case 12: V(0,(double *)) = ag_rp_12(V(0,(double *)), V(2,(double *))); break;
668 case 13: V(0,(double *)) = ag_rp_13(V(1,(double *))); break;
669 case 14: V(0,(double *)) = ag_rp_14(V(0,(int *))); break;
670 case 15: V(0,(double *)) = ag_rp_15(V(0,(double *)), V(1,(int *))); break;
671 case 16: V(0,(double *)) = ag_rp_16(V(0,(int *))); break;
672 case 17: V(0,(double *)) = ag_rp_17(V(0,(int *)), V(1,(double *))); break;
673 }
674 }
675
676 #define TOKEN_NAMES ffc-wa_token_names
677 const char *const ffc-wa_token_names[47] = {
678 "calculator",
679 "white space",
680 "real",
681 "calculator",
682 "calculation",
683 "",
684 "'\\n'",
685 "",
686 "",
687 "",
688 "eof",
689 "expression",
690 "name",
691 "'='",
692 "term",
693 "'+'",
694 "'-'",
695 "factor",
696 "'*'",
697 "'/'",
698 "'('",
699 "')'",
700 "",
701 "\"/*\"",
702 "",
703 "",
704 "",
705 "\"*/\"",
706 "",
707 "integer part",
708 "'.'",
709 "fraction part",
710 "",
711 "digit",
712 "",
713 "",
714 "",
715 "'\\n'",
716 "'='",
717 "'+'",
718 "'-'",
719 "'*'",
720 "'/'",
721 "real",
722 "')'",
723 "'('",
724 "",
725
726 };
727
728
729 static const unsigned char ag_ctn[] = {
730 0,0, 1,1, 0,0, 0,0, 0,0, 1,2, 43,1, 43,1, 0,0, 17,1, 17,1, 17,1,
731 17,1, 12,1, 14,1, 4,1, 11,1, 0,0, 0,0, 0,0, 31,1, 43,2, 11,1, 0,0,
732 14,2, 0,0, 14,2, 0,0, 4,2, 11,2, 0,0, 11,2, 0,0, 0,0, 11,1, 14,1,
733 14,1
734 };
735
736 #ifndef MISSING_FORMAT
737 #define MISSING_FORMAT "Missing %s"
738 #endif
739 #ifndef UNEXPECTED_FORMAT
740 #define UNEXPECTED_FORMAT "Unexpected %s"
741 #endif
742 #ifndef UNNAMED_TOKEN
743 #define UNNAMED_TOKEN "input"
744 #endif
745
746
747 static void ag_diagnose(void) {
748 int ag_snd = (PCB).sn;
749 int ag_k = ag_sbt[ag_snd];
750
751 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) {
752 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
753 }
754 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8
755 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1
756 && *TOKEN_NAMES[ag_tstt[ag_k]]) {
757 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
758 }
759 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
760 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]);
761 }
762 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') {
763 char buf[20];
764 sprintf(buf, "\'%c\'", (char) (*(PCB).lab));
765 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf);
766 }
767 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN);
768 (PCB).error_message = (PCB).ag_msg;
769
770
771 {
772 int ag_sx, ag_t;
773
774 ag_sx = (PCB).ssx;
775 (PCB).ss[ag_sx] = (PCB).sn;
776 do {
777 while (ag_sx && ag_ctn[2*(ag_snd = (PCB).ss[ag_sx])] == 0) ag_sx--;
778 if (ag_sx) {
779 ag_t = ag_ctn[2*ag_snd];
780 ag_sx -= ag_ctn[2*ag_snd +1];
781 ag_snd = (PCB).ss[ag_sx];
782 }
783 else {
784 ag_snd = 0;
785 ag_t = ag_ptt[0];
786 }
787 } while (ag_sx && *TOKEN_NAMES[ag_t]==0);
788 if (*TOKEN_NAMES[ag_t] == 0) ag_t = 0;
789 (PCB).error_frame_ssx = ag_sx;
790 (PCB).error_frame_token = (ffc-wa_token_type) ag_t;
791 }
792
793
794 }
795 static int ag_action_1_r_proc(void);
796 static int ag_action_2_r_proc(void);
797 static int ag_action_3_r_proc(void);
798 static int ag_action_4_r_proc(void);
799 static int ag_action_1_s_proc(void);
800 static int ag_action_3_s_proc(void);
801 static int ag_action_1_proc(void);
802 static int ag_action_2_proc(void);
803 static int ag_action_3_proc(void);
804 static int ag_action_4_proc(void);
805 static int ag_action_5_proc(void);
806 static int ag_action_6_proc(void);
807 static int ag_action_7_proc(void);
808 static int ag_action_8_proc(void);
809 static int ag_action_9_proc(void);
810 static int ag_action_10_proc(void);
811 static int ag_action_11_proc(void);
812 static int ag_action_8_proc(void);
813
814
815 static int (*const ag_r_procs_scan[])(void) = {
816 ag_action_1_r_proc,
817 ag_action_2_r_proc,
818 ag_action_3_r_proc,
819 ag_action_4_r_proc
820 };
821
822 static int (*const ag_s_procs_scan[])(void) = {
823 ag_action_1_s_proc,
824 ag_action_2_r_proc,
825 ag_action_3_s_proc,
826 ag_action_4_r_proc
827 };
828
829 static int (*const ag_gt_procs_scan[])(void) = {
830 ag_action_1_proc,
831 ag_action_2_proc,
832 ag_action_3_proc,
833 ag_action_4_proc,
834 ag_action_5_proc,
835 ag_action_6_proc,
836 ag_action_7_proc,
837 ag_action_8_proc,
838 ag_action_9_proc,
839 ag_action_10_proc,
840 ag_action_11_proc,
841 ag_action_8_proc
842 };
843
844
845 static int ag_rns(int ag_t, int *ag_sx, int ag_snd) {
846 while (1) {
847 int ag_act, ag_k = ag_sbt[ag_snd], ag_lim = ag_sbt[ag_snd+1];
848 int ag_p;
849
850 while (ag_k < ag_lim && ag_tstt[ag_k] != ag_t) ag_k++;
851 if (ag_k == ag_lim) break;
852 ag_act = ag_astt[ag_k];
853 ag_p = ag_pstt[ag_k];
854 if (ag_act == ag_action_2) return ag_p;
855 if (ag_act == ag_action_10 || ag_act == ag_action_11) {
856 (*ag_sx)--;
857 return ag_snd;
858 }
859 if (ag_act != ag_action_3 &&
860 ag_act != ag_action_4) break;
861 *ag_sx -= (ag_fl[ag_p] - 1);
862 ag_snd = (PCB).ss[*ag_sx];
863 ag_t = ag_ptt[ag_p];
864 }
865 return 0;
866 }
867
868 static int ag_jns(int ag_t) {
869 int ag_k;
870
871 ag_k = ag_sbt[(PCB).sn];
872 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
873 while (1) {
874 int ag_p = ag_pstt[ag_k];
875 int ag_sd;
876
877 switch (ag_astt[ag_k]) {
878 case ag_action_2:
879 (PCB).ss[(PCB).ssx] = (PCB).sn;
880 return ag_p;
881 case ag_action_10:
882 case ag_action_11:
883 return (PCB).ss[(PCB).ssx--];
884 case ag_action_9:
885 (PCB).ss[(PCB).ssx] = (PCB).sn;
886 (PCB).ssx++;
887 (PCB).sn = ag_p;
888 ag_k = ag_sbt[(PCB).sn];
889 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
890 continue;
891 case ag_action_3:
892 case ag_action_4:
893 ag_sd = ag_fl[ag_p] - 1;
894 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
895 else (PCB).ss[(PCB).ssx] = (PCB).sn;
896 ag_t = ag_ptt[ag_p];
897 ag_k = ag_sbt[(PCB).sn+1];
898 while (ag_tstt[--ag_k] != ag_t);
899 continue;
900 case ag_action_5:
901 case ag_action_6:
902 if (ag_fl[ag_p]) break;
903 (PCB).sn = ag_rns(ag_ptt[ag_p],&(PCB).ssx, (PCB).sn);
904 (PCB).ss[++(PCB).ssx] = (PCB).sn;
905 ag_k = ag_sbt[(PCB).sn];
906 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
907 continue;
908 }
909 break;
910 }
911 return 0;
912 }
913
914
915 static int ag_atx(int ag_t, int *ag_sx, int ag_snd) {
916 int ag_k, ag_f;
917 int ag_save_btsx = (PCB).btsx;
918 int ag_flag = 1;
919
920 while (1) {
921 int ag_a;
922
923 (PCB).bts[128 - ++(PCB).btsx] = *ag_sx;
924 (PCB).ss[128 - (PCB).btsx] = (PCB).ss[*ag_sx];
925 (PCB).ss[*ag_sx] = ag_snd;
926 ag_k = ag_sbt[ag_snd];
927 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
928 ag_a = ag_astt[ag_k];
929 if (ag_a == ag_action_2 ||
930 ag_a == ag_action_3 ||
931 ag_a == ag_action_10 ||
932 ag_a == ag_action_11 ||
933 ag_a == ag_action_1 ||
934 ag_a == ag_action_4) break;
935 if ((ag_a == ag_action_5 ||
936 ag_a == ag_action_6) &&
937 (ag_k = ag_fl[ag_f = ag_pstt[ag_k]]) == 0) {
938 ag_snd = ag_rns(ag_ptt[ag_f],ag_sx, (PCB).ss[*ag_sx]);
939 (*ag_sx)++;
940 continue;
941 }
942 if (ag_a == ag_action_9) {
943 ag_snd = ag_pstt[ag_k];
944 (*ag_sx)++;
945 continue;
946 }
947 ag_flag = 0;
948 break;
949 }
950 while ((PCB).btsx > ag_save_btsx) {
951 *ag_sx = (PCB).bts[128 - (PCB).btsx];
952 (PCB).ss[*ag_sx] = (PCB).ss[128 - (PCB).btsx--];
953 }
954 return ag_flag;
955 }
956
957
958 static int ag_tst_tkn(void) {
959 int ag_rk, ag_sx, ag_snd = (PCB).sn;
960
961 if ((PCB).rx < (PCB).fx) {
962 (PCB).input_code = (PCB).lab[(PCB).rx++];
963 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
964 else {
965 GET_INPUT;
966 (PCB).lab[(PCB).fx++] = (PCB).input_code;
967 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);
968 (PCB).rx++;
969 }
970 if (ag_key_index[(PCB).sn]) {
971 unsigned ag_k = ag_key_index[(PCB).sn];
972 int ag_ch = CONVERT_CASE((PCB).input_code);
973 if (ag_ch < 255) {
974 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
975 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
976 }
977 }
978 for (ag_rk = 0; ag_rk < (PCB).ag_lrss; ag_rk += 2) {
979 ag_sx = (PCB).ag_rss[ag_rk];
980 if (ag_sx > (PCB).ssx || ag_sx > (PCB).ag_min_depth) continue;
981 (PCB).sn = (PCB).ag_rss[ag_rk + 1];
982 if (ag_atx((PCB).token_number, &ag_sx, (PCB).sn)) break;
983 }
984 (PCB).sn = ag_snd;
985 return ag_rk;
986 }
987
988 static void ag_set_error_procs(void);
989
990 static void ag_auto_resynch(void) {
991 int ag_sx, ag_rk;
992 int ag_rk1, ag_rk2, ag_tk1;
993 DELETE_WRAPPERS;
994 (PCB).ss[(PCB).ssx] = (PCB).sn;
995 if ((PCB).ag_error_depth && (PCB).ag_min_depth >= (PCB).ag_error_depth) {
996 (PCB).ssx = (PCB).ag_error_depth;
997 (PCB).sn = (PCB).ss[(PCB).ssx];
998 }
999 else {
1000 ag_diagnose();
1001 SYNTAX_ERROR;
1002 if ((PCB).exit_flag != AG_RUNNING_CODE) return;
1003 (PCB).ag_error_depth = (PCB).ag_min_depth = 0;
1004 (PCB).ag_lrss = 0;
1005 (PCB).ss[ag_sx = (PCB).ssx] = (PCB).sn;
1006 (PCB).ag_min_depth = (PCB).ag_rss[(PCB).ag_lrss++] = ag_sx;
1007 (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn;
1008 while (ag_sx && (PCB).ag_lrss < 2*128) {
1009 int ag_t = 0, ag_x, ag_s, ag_sxs = ag_sx;
1010
1011 while (ag_sx && (ag_t = ag_ctn[2*(PCB).sn]) == 0) (PCB).sn = (PCB).ss[--ag_sx];
1012 if (ag_t) (PCB).sn = (PCB).ss[ag_sx -= ag_ctn[2*(PCB).sn +1]];
1013 else {
1014 if (ag_sx == 0) (PCB).sn = 0;
1015 ag_t = ag_ptt[0];
1016 }
1017 if ((ag_s = ag_rns(ag_t, &ag_sx, (PCB).sn)) == 0) break;
1018 for (ag_x = 0; ag_x < (PCB).ag_lrss; ag_x += 2)
1019 if ((PCB).ag_rss[ag_x] == ag_sx + 1 && (PCB).ag_rss[ag_x+1] == ag_s) break;
1020 if (ag_x == (PCB).ag_lrss) {
1021 (PCB).ag_rss[(PCB).ag_lrss++] = ++ag_sx;
1022 (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn = ag_s;
1023 }
1024 else if (ag_sx >= ag_sxs) ag_sx--;
1025 }
1026 ag_set_error_procs();
1027 }
1028 (PCB).rx = 0;
1029 if ((PCB).ssx > (PCB).ag_min_depth) (PCB).ag_min_depth = (PCB).ssx;
1030 while (1) {
1031 ag_rk1 = ag_tst_tkn();
1032 if ((PCB).token_number == 10)
1033 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;}
1034 if (ag_rk1 < (PCB).ag_lrss) break;
1035 {(PCB).rx = 1; ag_track();}
1036 }
1037 ag_tk1 = (PCB).token_number;
1038 ag_track();
1039 ag_rk2 = ag_tst_tkn();
1040 if (ag_rk2 < ag_rk1) {ag_rk = ag_rk2; ag_track();}
1041 else {ag_rk = ag_rk1; (PCB).token_number = (ffc-wa_token_type) ag_tk1; (PCB).rx = 0;}
1042 (PCB).ag_min_depth = (PCB).ssx = (PCB).ag_rss[ag_rk++];
1043 (PCB).sn = (PCB).ss[(PCB).ssx] = (PCB).ag_rss[ag_rk];
1044 (PCB).sn = ag_jns((PCB).token_number);
1045 if ((PCB).ag_error_depth == 0 || (PCB).ag_error_depth > (PCB).ssx)
1046 (PCB).ag_error_depth = (PCB).ssx;
1047 if (++(PCB).ssx >= 128) {
1048 (PCB).exit_flag = AG_STACK_ERROR_CODE;
1049 PARSER_STACK_OVERFLOW;
1050 return;
1051 }
1052 (PCB).ss[(PCB).ssx] = (PCB).sn;
1053 (PCB).ag_tmp_depth = (PCB).ag_min_depth;
1054 (PCB).rx = 0;
1055 return;
1056 }
1057
1058
1059 static int ag_action_10_proc(void) {
1060 int ag_t = (PCB).token_number;
1061 (PCB).btsx = 0, (PCB).drt = -1;
1062 do {
1063 ag_track();
1064 if ((PCB).rx < (PCB).fx) {
1065 (PCB).input_code = (PCB).lab[(PCB).rx++];
1066 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
1067 else {
1068 GET_INPUT;
1069 (PCB).lab[(PCB).fx++] = (PCB).input_code;
1070 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);
1071 (PCB).rx++;
1072 }
1073 if (ag_key_index[(PCB).sn]) {
1074 unsigned ag_k = ag_key_index[(PCB).sn];
1075 int ag_ch = CONVERT_CASE((PCB).input_code);
1076 if (ag_ch < 255) {
1077 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1078 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
1079 }
1080 }
1081 } while ((PCB).token_number == (ffc-wa_token_type) ag_t);
1082 (PCB).rx = 0;
1083 return 1;
1084 }
1085
1086 static int ag_action_11_proc(void) {
1087 int ag_t = (PCB).token_number;
1088
1089 (PCB).btsx = 0, (PCB).drt = -1;
1090 do {
1091 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1092 (PCB).ssx--;
1093 ag_track();
1094 ag_ra();
1095 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
1096 (PCB).ssx++;
1097 if ((PCB).rx < (PCB).fx) {
1098 (PCB).input_code = (PCB).lab[(PCB).rx++];
1099 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
1100 else {
1101 GET_INPUT;
1102 (PCB).lab[(PCB).fx++] = (PCB).input_code;
1103 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);
1104 (PCB).rx++;
1105 }
1106 if (ag_key_index[(PCB).sn]) {
1107 unsigned ag_k = ag_key_index[(PCB).sn];
1108 int ag_ch = CONVERT_CASE((PCB).input_code);
1109 if (ag_ch < 255) {
1110 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1111 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
1112 }
1113 }
1114 }
1115 while ((PCB).token_number == (ffc-wa_token_type) ag_t);
1116 (PCB).rx = 0;
1117 return 1;
1118 }
1119
1120 static int ag_action_3_r_proc(void) {
1121 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1122 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1123 (PCB).btsx = 0, (PCB).drt = -1;
1124 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1125 ag_ra();
1126 return (PCB).exit_flag == AG_RUNNING_CODE;
1127 }
1128
1129 static int ag_action_3_s_proc(void) {
1130 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1131 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1132 (PCB).btsx = 0, (PCB).drt = -1;
1133 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1134 ag_ra();
1135 return (PCB).exit_flag == AG_RUNNING_CODE;
1136 }
1137
1138 static int ag_action_4_r_proc(void) {
1139 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1140 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1141 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1142 return 1;
1143 }
1144
1145 static int ag_action_2_proc(void) {
1146 (PCB).btsx = 0, (PCB).drt = -1;
1147 if ((PCB).ssx >= 128) {
1148 (PCB).exit_flag = AG_STACK_ERROR_CODE;
1149 PARSER_STACK_OVERFLOW;
1150 }
1151 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1152 (PCB).ss[(PCB).ssx] = (PCB).sn;
1153 (PCB).ssx++;
1154 (PCB).sn = (PCB).ag_ap;
1155 ag_track();
1156 return 0;
1157 }
1158
1159 static int ag_action_9_proc(void) {
1160 if ((PCB).drt == -1) {
1161 (PCB).drt=(PCB).token_number;
1162 (PCB).dssx=(PCB).ssx;
1163 (PCB).dsn=(PCB).sn;
1164 }
1165 ag_prot();
1166 (PCB).vs[(PCB).ssx] = ag_null_value;
1167 (PCB).ss[(PCB).ssx] = (PCB).sn;
1168 (PCB).ssx++;
1169 (PCB).sn = (PCB).ag_ap;
1170 (PCB).rx = 0;
1171 return (PCB).exit_flag == AG_RUNNING_CODE;
1172 }
1173
1174 static int ag_action_2_r_proc(void) {
1175 (PCB).ssx++;
1176 (PCB).sn = (PCB).ag_ap;
1177 return 0;
1178 }
1179
1180 static int ag_action_7_proc(void) {
1181 --(PCB).ssx;
1182 (PCB).rx = 0;
1183 (PCB).exit_flag = AG_SUCCESS_CODE;
1184 return 0;
1185 }
1186
1187 static int ag_action_1_proc(void) {
1188 ag_track();
1189 (PCB).exit_flag = AG_SUCCESS_CODE;
1190 return 0;
1191 }
1192
1193 static int ag_action_1_r_proc(void) {
1194 (PCB).exit_flag = AG_SUCCESS_CODE;
1195 return 0;
1196 }
1197
1198 static int ag_action_1_s_proc(void) {
1199 (PCB).exit_flag = AG_SUCCESS_CODE;
1200 return 0;
1201 }
1202
1203 static int ag_action_4_proc(void) {
1204 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1205 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1206 (PCB).btsx = 0, (PCB).drt = -1;
1207 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1208 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1209 else (PCB).ss[(PCB).ssx] = (PCB).sn;
1210 ag_track();
1211 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1212 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1213 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1214 do {
1215 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1216 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1217 else ag_t2 = ag_tx;
1218 } while (ag_t1 < ag_t2);
1219 (PCB).ag_ap = ag_pstt[ag_t1];
1220 if ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break;
1221 }
1222 return 0;
1223 }
1224
1225 static int ag_action_3_proc(void) {
1226 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1227 (PCB).btsx = 0, (PCB).drt = -1;
1228 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1229 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1230 else (PCB).ss[(PCB).ssx] = (PCB).sn;
1231 ag_track();
1232 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1233 ag_ra();
1234 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1235 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1236 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1237 do {
1238 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1239 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1240 else ag_t2 = ag_tx;
1241 } while (ag_t1 < ag_t2);
1242 (PCB).ag_ap = ag_pstt[ag_t1];
1243 if ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break;
1244 }
1245 return 0;
1246 }
1247
1248 static int ag_action_8_proc(void) {
1249 ag_undo();
1250 (PCB).rx = 0;
1251 ag_auto_resynch();
1252 return (PCB).exit_flag == AG_RUNNING_CODE;
1253 }
1254
1255 static int ag_action_5_proc(void) {
1256 int ag_sd = ag_fl[(PCB).ag_ap];
1257 (PCB).btsx = 0, (PCB).drt = -1;
1258 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1259 else {
1260 (PCB).ss[(PCB).ssx] = (PCB).sn;
1261 }
1262 (PCB).rx = 0;
1263 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1264 ag_ra();
1265 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1266 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1267 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1268 do {
1269 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1270 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1271 else ag_t2 = ag_tx;
1272 } while (ag_t1 < ag_t2);
1273 (PCB).ag_ap = ag_pstt[ag_t1];
1274 if ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break;
1275 }
1276 return (PCB).exit_flag == AG_RUNNING_CODE;
1277 }
1278
1279 static int ag_action_6_proc(void) {
1280 int ag_sd = ag_fl[(PCB).ag_ap];
1281 (PCB).reduction_token = (ffc-wa_token_type) ag_ptt[(PCB).ag_ap];
1282 if ((PCB).drt == -1) {
1283 (PCB).drt=(PCB).token_number;
1284 (PCB).dssx=(PCB).ssx;
1285 (PCB).dsn=(PCB).sn;
1286 }
1287 if (ag_sd) {
1288 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1289 }
1290 else {
1291 ag_prot();
1292 (PCB).vs[(PCB).ssx] = ag_null_value;
1293 (PCB).ss[(PCB).ssx] = (PCB).sn;
1294 }
1295 (PCB).rx = 0;
1296 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1297 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1298 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1299 do {
1300 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1301 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1302 else ag_t2 = ag_tx;
1303 } while (ag_t1 < ag_t2);
1304 (PCB).ag_ap = ag_pstt[ag_t1];
1305 if ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break;
1306 }
1307 return (PCB).exit_flag == AG_RUNNING_CODE;
1308 }
1309
1310
1311 static void ag_check_depth(int ag_fl) {
1312 int ag_sx = (PCB).ssx - ag_fl;
1313 if ((PCB).ag_error_depth && ag_sx < (PCB).ag_tmp_depth) (PCB).ag_tmp_depth = ag_sx;
1314 }
1315
1316 static int ag_action_3_er_proc(void) {
1317 ag_check_depth(ag_fl[(PCB).ag_ap] - 1);
1318 return ag_action_4_r_proc();
1319 }
1320
1321 static int ag_action_2_e_proc(void) {
1322 ag_action_2_proc();
1323 (PCB).ag_min_depth = (PCB).ag_tmp_depth;
1324 return 0;
1325 }
1326
1327 static int ag_action_4_e_proc(void) {
1328 ag_check_depth(ag_fl[(PCB).ag_ap] - 1);
1329 (PCB).ag_min_depth = (PCB).ag_tmp_depth;
1330 return ag_action_4_proc();
1331 }
1332
1333 static int ag_action_6_e_proc(void) {
1334 ag_check_depth(ag_fl[(PCB).ag_ap]);
1335 return ag_action_6_proc();
1336 }
1337
1338 static int ag_action_11_e_proc(void) {
1339 return ag_action_10_proc();
1340 }
1341
1342 static int (*ag_r_procs_error[])(void) = {
1343 ag_action_1_r_proc,
1344 ag_action_2_r_proc,
1345 ag_action_3_er_proc,
1346 ag_action_3_er_proc
1347 };
1348
1349 static int (*ag_s_procs_error[])(void) = {
1350 ag_action_1_s_proc,
1351 ag_action_2_r_proc,
1352 ag_action_3_er_proc,
1353 ag_action_3_er_proc
1354 };
1355
1356 static int (*ag_gt_procs_error[])(void) = {
1357 ag_action_1_proc,
1358 ag_action_2_e_proc,
1359 ag_action_4_e_proc,
1360 ag_action_4_e_proc,
1361 ag_action_6_e_proc,
1362 ag_action_6_e_proc,
1363 ag_action_7_proc,
1364 ag_action_8_proc,
1365 ag_action_9_proc,
1366 ag_action_10_proc,
1367 ag_action_11_e_proc,
1368 ag_action_8_proc
1369 };
1370
1371 static void ag_set_error_procs(void) {
1372 (PCB).gt_procs = ag_gt_procs_error;
1373 (PCB).r_procs = ag_r_procs_error;
1374 (PCB).s_procs = ag_s_procs_error;
1375 }
1376
1377
1378 void init_ffc-wa(void) {
1379 (PCB).rx = (PCB).fx = 0;
1380 (PCB).gt_procs = ag_gt_procs_scan;
1381 (PCB).r_procs = ag_r_procs_scan;
1382 (PCB).s_procs = ag_s_procs_scan;
1383 (PCB).ag_error_depth = (PCB).ag_min_depth = (PCB).ag_tmp_depth = 0;
1384 (PCB).ag_resynch_active = 0;
1385 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
1386 (PCB).exit_flag = AG_RUNNING_CODE;
1387 (PCB).line = FIRST_LINE;
1388 (PCB).column = FIRST_COLUMN;
1389 (PCB).btsx = 0, (PCB).drt = -1;
1390 }
1391
1392 void ffc-wa(void) {
1393 init_ffc-wa();
1394 (PCB).exit_flag = AG_RUNNING_CODE;
1395 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1396 unsigned ag_t1 = ag_sbt[(PCB).sn];
1397 if (ag_tstt[ag_t1]) {
1398 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
1399 if ((PCB).rx < (PCB).fx) {
1400 (PCB).input_code = (PCB).lab[(PCB).rx++];
1401 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
1402 else {
1403 GET_INPUT;
1404 (PCB).lab[(PCB).fx++] = (PCB).input_code;
1405 (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);
1406 (PCB).rx++;
1407 }
1408 if (ag_key_index[(PCB).sn]) {
1409 unsigned ag_k = ag_key_index[(PCB).sn];
1410 int ag_ch = CONVERT_CASE((PCB).input_code);
1411 if (ag_ch < 255) {
1412 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1413 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
1414 }
1415 }
1416 do {
1417 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1418 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
1419 ag_t1 = ag_tx + 1;
1420 else ag_t2 = ag_tx;
1421 } while (ag_t1 < ag_t2);
1422 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number)
1423 ag_t1 = ag_sbe[(PCB).sn];
1424 }
1425 (PCB).ag_ap = ag_pstt[ag_t1];
1426 (*(PCB).gt_procs[ag_astt[ag_t1]])();
1427 }
1428 }
1429
1430