comparison tests/agcl/parsifal/good/t201a.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
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 T201A_H
27 #include "t201a.h"
28 #endif
29
30 #ifndef T201A_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 t201a_pcb_type t201a_pcb;
44 #define PCB t201a_pcb
45 #define CHANGE_REDUCTION(x) t201a_change_reduction(t201a_##x##_token)
46 int t201a_change_reduction(t201a_token_type);
47
48
49 #ifndef CONVERT_CASE
50 #define CONVERT_CASE(c) (c)
51 #endif
52 #ifndef TAB_SPACING
53 #define TAB_SPACING 8
54 #endif
55
56 #define ag_rp_1() (1)
57
58 #define ag_rp_2() (2)
59
60 #define ag_rp_3()
61
62 #define ag_rp_4()
63
64 #define ag_rp_5()
65
66 #define ag_rp_7() (4)
67
68
69 #define READ_COUNTS
70 #define WRITE_COUNTS
71 #undef V
72 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
73 #undef VS
74 #define VS(i) (PCB).vs[(PCB).ssx + i]
75
76 #ifndef GET_CONTEXT
77 #define GET_CONTEXT CONTEXT = (PCB).input_context
78 #endif
79
80 typedef enum {
81 ag_action_1,
82 ag_action_2,
83 ag_action_3,
84 ag_action_4,
85 ag_action_5,
86 ag_action_6,
87 ag_action_7,
88 ag_action_8,
89 ag_action_9,
90 ag_action_10,
91 ag_action_11,
92 ag_action_12
93 } ag_parser_action;
94
95
96 #ifndef NULL_VALUE_INITIALIZER
97 #define NULL_VALUE_INITIALIZER = 0
98 #endif
99
100 static int const ag_null_value NULL_VALUE_INITIALIZER;
101
102 static const unsigned char ag_rpx[] = {
103 0, 1, 2, 3, 4, 5, 1, 6
104 };
105
106 static const unsigned char ag_key_itt[] = {
107 0
108 };
109
110 static const unsigned short ag_key_pt[] = {
111 0
112 };
113
114 static const unsigned char ag_key_ch[] = {
115 0, 48,255
116 };
117
118 static const unsigned char ag_key_act[] = {
119 0,3,4
120 };
121
122 static const unsigned char ag_key_parm[] = {
123 0, 10, 0
124 };
125
126 static const unsigned char ag_key_jmp[] = {
127 0, 0, 0
128 };
129
130 static const unsigned char ag_key_index[] = {
131 1, 0, 0, 0, 0, 0, 0, 0, 0
132 };
133
134 static const unsigned char ag_key_ends[] = {
135 120,0,
136 };
137 #define AG_TCV(x) (((int)(x) >= 0 && (int)(x) <= 255) ? ag_tcv[(x)] : 0)
138
139 static const unsigned char ag_tcv[] = {
140 20, 16, 16, 16, 16, 16, 16, 16, 16, 23, 23, 23, 23, 23, 23, 23, 23, 23,
141 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 17, 23, 23,
142 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 13, 6, 6, 6, 6, 6, 6,
143 6, 6, 6, 6, 23, 23, 23, 23, 23, 23, 23, 8, 8, 8, 8, 8, 8, 21,
144 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
145 21, 23, 23, 23, 23, 23, 23, 7, 7, 7, 7, 7, 7, 21, 21, 21, 21, 21,
146 21, 21, 21, 21, 22, 22, 21, 21, 21, 21, 21, 21, 21, 21, 21, 23, 15, 23,
147 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
148 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
149 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
150 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
151 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
152 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
153 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
154 23, 23, 23, 23
155 };
156
157 #ifndef SYNTAX_ERROR
158 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
159 (PCB).error_message, (PCB).line, (PCB).column)
160 #endif
161
162 #ifndef FIRST_LINE
163 #define FIRST_LINE 1
164 #endif
165
166 #ifndef FIRST_COLUMN
167 #define FIRST_COLUMN 1
168 #endif
169
170 #ifndef PARSER_STACK_OVERFLOW
171 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
172 "\nParser stack overflow, line %d, column %d\n",\
173 (PCB).line, (PCB).column);}
174 #endif
175
176 #ifndef REDUCTION_TOKEN_ERROR
177 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
178 "\nReduction token error, line %d, column %d\n", \
179 (PCB).line, (PCB).column);}
180 #endif
181
182
183 typedef enum
184 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
185 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
186
187 #ifndef GET_INPUT
188 #define GET_INPUT ((PCB).input_code = getchar())
189 #endif
190
191
192 static int ag_look_ahead(void) {
193 if ((PCB).rx < (PCB).fx) {
194 return CONVERT_CASE((PCB).lab[(PCB).rx++]);
195 }
196 GET_INPUT;
197 (PCB).fx++;
198 return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code);
199 }
200
201 static void ag_get_key_word(int ag_k) {
202 int save_index = (PCB).rx;
203 const unsigned char *sp;
204 int ag_ch;
205 while (1) {
206 switch (ag_key_act[ag_k]) {
207 case ag_cf_end_key:
208 sp = ag_key_ends + ag_key_jmp[ag_k];
209 do {
210 if ((ag_ch = *sp++) == 0) {
211 int ag_k1 = ag_key_parm[ag_k];
212 int ag_k2 = ag_key_pt[ag_k1];
213 if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail;
214 (PCB).rx--;
215 (PCB).token_number = (t201a_token_type) ag_key_pt[ag_k1 + 1];
216 return;
217 }
218 } while (ag_look_ahead() == ag_ch);
219 goto ag_fail;
220 case ag_end_key:
221 sp = ag_key_ends + ag_key_jmp[ag_k];
222 do {
223 if ((ag_ch = *sp++) == 0) {
224 (PCB).token_number = (t201a_token_type) ag_key_parm[ag_k];
225 return;
226 }
227 } while (ag_look_ahead() == ag_ch);
228 case ag_no_match_key:
229 ag_fail:
230 (PCB).rx = save_index;
231 return;
232 case ag_cf_set_key: {
233 int ag_k1 = ag_key_parm[ag_k];
234 int ag_k2 = ag_key_pt[ag_k1];
235 ag_k = ag_key_jmp[ag_k];
236 if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break;
237 save_index = --(PCB).rx;
238 (PCB).token_number = (t201a_token_type) ag_key_pt[ag_k1+1];
239 break;
240 }
241 case ag_set_key:
242 save_index = (PCB).rx;
243 (PCB).token_number = (t201a_token_type) ag_key_parm[ag_k];
244 case ag_jmp_key:
245 ag_k = ag_key_jmp[ag_k];
246 ag_ch = ag_look_ahead();
247 break;
248 case ag_accept_key:
249 (PCB).token_number = (t201a_token_type) ag_key_parm[ag_k];
250 return;
251 case ag_cf_accept_key: {
252 int ag_k1 = ag_key_parm[ag_k];
253 int ag_k2 = ag_key_pt[ag_k1];
254 if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index;
255 else {
256 (PCB).rx--;
257 (PCB).token_number = (t201a_token_type) ag_key_pt[ag_k1+1];
258 }
259 return;
260 }
261 default:
262 /* not reachable; here to suppress compiler warnings */
263 goto ag_fail;
264 }
265 if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++;
266 if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) {
267 (PCB).rx = save_index;
268 return;
269 }
270 }
271 }
272
273
274 #ifndef AG_NEWLINE
275 #define AG_NEWLINE 10
276 #endif
277
278 #ifndef AG_RETURN
279 #define AG_RETURN 13
280 #endif
281
282 #ifndef AG_FORMFEED
283 #define AG_FORMFEED 12
284 #endif
285
286 #ifndef AG_TABCHAR
287 #define AG_TABCHAR 9
288 #endif
289
290 static void ag_track(void) {
291 int ag_k = 0;
292 while (ag_k < (PCB).rx) {
293 int ag_ch = (PCB).lab[ag_k++];
294 switch (ag_ch) {
295 case AG_NEWLINE:
296 (PCB).column = 1, (PCB).line++;
297 case AG_RETURN:
298 case AG_FORMFEED:
299 break;
300 case AG_TABCHAR:
301 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
302 break;
303 default:
304 (PCB).column++;
305 }
306 }
307 ag_k = 0;
308 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++];
309 (PCB).fx = ag_k;
310 (PCB).rx = 0;
311 }
312
313
314 static void ag_prot(void) {
315 int ag_k;
316 ag_k = 128 - ++(PCB).btsx;
317 if (ag_k <= (PCB).ssx) {
318 (PCB).exit_flag = AG_STACK_ERROR_CODE;
319 PARSER_STACK_OVERFLOW;
320 return;
321 }
322 (PCB).bts[(PCB).btsx] = (PCB).sn;
323 (PCB).bts[ag_k] = (PCB).ssx;
324 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
325 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
326 }
327
328 static void ag_undo(void) {
329 if ((PCB).drt == -1) return;
330 while ((PCB).btsx) {
331 int ag_k = 128 - (PCB).btsx;
332 (PCB).sn = (PCB).bts[(PCB).btsx--];
333 (PCB).ssx = (PCB).bts[ag_k];
334 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
335 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
336 }
337 (PCB).token_number = (t201a_token_type) (PCB).drt;
338 (PCB).ssx = (PCB).dssx;
339 (PCB).sn = (PCB).dsn;
340 (PCB).drt = -1;
341 }
342
343
344
345 static const int ag_rtt[] = {
346 4, 5, 0, 4, 5, 0, 4, 5, 0
347 };
348
349 static const unsigned char ag_tstt[] = {
350 22,21,17,15,13,10,8,7,6,0,1,9,11,12,19,
351 8,7,6,0,4,
352 23,22,21,17,16,15,13,8,7,6,0,
353 16,0,
354 23,22,17,15,13,6,0,
355 8,7,6,0,4,
356 6,0,
357 22,21,8,7,6,0,
358 20,0,
359
360 };
361
362
363 static unsigned const char ag_astt[55] = {
364 2,2,1,1,1,1,2,2,1,7,1,1,1,1,0,2,2,2,7,2,3,3,3,3,3,3,3,3,3,3,7,3,7,3,3,3,3,
365 3,3,7,2,2,2,5,2,9,5,10,10,10,10,10,5,3,7
366 };
367
368
369 static const unsigned char ag_pstt[] = {
370 1,1,2,3,4,1,1,1,6,0,7,5,6,8,0,
371 5,4,3,1,6,
372 15,15,15,15,15,15,15,15,15,15,2,
373 14,3,
374 13,13,13,13,13,13,4,
375 5,4,3,12,7,
376 9,11,
377 2,2,2,2,2,10,
378 16,8,
379
380 };
381
382
383 static const unsigned char ag_sbt[] = {
384 0, 15, 20, 31, 33, 40, 45, 47, 53, 55
385 };
386
387
388 static const unsigned char ag_sbe[] = {
389 9, 18, 30, 32, 39, 43, 46, 52, 54, 55
390 };
391
392
393 static const unsigned char ag_fl[] = {
394 1,1,2,1,1,1,2,2,1,2,1,1,1,2,2,2,2
395 };
396
397 static const unsigned char ag_ptt[] = {
398 0, 1, 1, 4, 4, 4, 9, 9, 11, 11, 12, 12, 12, 12, 12, 12, 19
399 };
400
401 static const unsigned char *ag_valid(int ag_k) {
402 const unsigned char *ag_tp = &ag_tstt[ag_sbt[(PCB).sn+1]];
403 while (*--ag_tp != (unsigned char) ag_k) if (*ag_tp == 0) return NULL;
404 return ag_tp;
405 }
406
407 int t201a_change_reduction(t201a_token_type ag_k) {
408 if (!ag_valid(ag_k)) return 0;
409 (PCB).reduction_token = ag_k;
410 return 1;
411 }
412
413 static void ag_default(const int *ag_tp) {
414 (PCB).ag_dsn = (PCB).sn;
415 (PCB).ag_dtl = ag_tp;
416 while (!ag_valid((t201a_token_type) *ag_tp)) ag_tp++;
417 (PCB).reduction_token = (t201a_token_type) *ag_tp;
418 }
419
420
421
422 static void ag_ra(void)
423 {
424 switch(ag_rpx[(PCB).ag_ap]) {
425 case 1: ag_rp_1(); break;
426 case 2: ag_rp_2(); break;
427 case 3: ag_default(&ag_rtt[0]); ag_rp_3(); break;
428 case 4: ag_default(&ag_rtt[3]); ag_rp_4(); break;
429 case 5: ag_default(&ag_rtt[6]); ag_rp_5(); break;
430 case 6: ag_rp_7(); break;
431 }
432 }
433
434 #define TOKEN_NAMES t201a_token_names
435 const char *const t201a_token_names[24] = {
436 "grammar",
437 "name",
438 "letter",
439 "",
440 "hex digit",
441 "text",
442 "digit",
443 "",
444 "",
445 "hex number",
446 "\"0x\"",
447 "number",
448 "token",
449 "'/'",
450 "printable",
451 "'|'",
452 "nonprintable",
453 "'!'",
454 "universe",
455 "grammar",
456 "eof",
457 "",
458 "",
459 "",
460
461 };
462
463 #ifndef MISSING_FORMAT
464 #define MISSING_FORMAT "Missing %s"
465 #endif
466 #ifndef UNEXPECTED_FORMAT
467 #define UNEXPECTED_FORMAT "Unexpected %s"
468 #endif
469 #ifndef UNNAMED_TOKEN
470 #define UNNAMED_TOKEN "input"
471 #endif
472
473
474 static void ag_diagnose(void) {
475 int ag_snd = (PCB).sn;
476 int ag_k = ag_sbt[ag_snd];
477
478 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) {
479 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
480 }
481 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8
482 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1
483 && *TOKEN_NAMES[ag_tstt[ag_k]]) {
484 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
485 }
486 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
487 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]);
488 }
489 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') {
490 char buf[20];
491 sprintf(buf, "\'%c\'", (char) (*(PCB).lab));
492 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf);
493 }
494 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN);
495 (PCB).error_message = (PCB).ag_msg;
496
497
498 }
499 static int ag_action_1_r_proc(void);
500 static int ag_action_2_r_proc(void);
501 static int ag_action_3_r_proc(void);
502 static int ag_action_4_r_proc(void);
503 static int ag_action_1_s_proc(void);
504 static int ag_action_3_s_proc(void);
505 static int ag_action_1_proc(void);
506 static int ag_action_2_proc(void);
507 static int ag_action_3_proc(void);
508 static int ag_action_4_proc(void);
509 static int ag_action_5_proc(void);
510 static int ag_action_6_proc(void);
511 static int ag_action_7_proc(void);
512 static int ag_action_8_proc(void);
513 static int ag_action_9_proc(void);
514 static int ag_action_10_proc(void);
515 static int ag_action_11_proc(void);
516 static int ag_action_8_proc(void);
517
518
519 static int (*const ag_r_procs_scan[])(void) = {
520 ag_action_1_r_proc,
521 ag_action_2_r_proc,
522 ag_action_3_r_proc,
523 ag_action_4_r_proc
524 };
525
526 static int (*const ag_s_procs_scan[])(void) = {
527 ag_action_1_s_proc,
528 ag_action_2_r_proc,
529 ag_action_3_s_proc,
530 ag_action_4_r_proc
531 };
532
533 static int (*const ag_gt_procs_scan[])(void) = {
534 ag_action_1_proc,
535 ag_action_2_proc,
536 ag_action_3_proc,
537 ag_action_4_proc,
538 ag_action_5_proc,
539 ag_action_6_proc,
540 ag_action_7_proc,
541 ag_action_8_proc,
542 ag_action_9_proc,
543 ag_action_10_proc,
544 ag_action_11_proc,
545 ag_action_8_proc
546 };
547
548
549 static int ag_action_10_proc(void) {
550 int ag_t = (PCB).token_number;
551 (PCB).btsx = 0, (PCB).drt = -1;
552 do {
553 ag_track();
554 if ((PCB).rx < (PCB).fx) {
555 (PCB).input_code = (PCB).lab[(PCB).rx++];
556 (PCB).token_number = (t201a_token_type) AG_TCV((PCB).input_code);}
557 else {
558 GET_INPUT;
559 (PCB).lab[(PCB).fx++] = (PCB).input_code;
560 (PCB).token_number = (t201a_token_type) AG_TCV((PCB).input_code);
561 (PCB).rx++;
562 }
563 if (ag_key_index[(PCB).sn]) {
564 unsigned ag_k = ag_key_index[(PCB).sn];
565 int ag_ch = CONVERT_CASE((PCB).input_code);
566 if (ag_ch < 255) {
567 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
568 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
569 }
570 }
571 } while ((PCB).token_number == (t201a_token_type) ag_t);
572 (PCB).rx = 0;
573 return 1;
574 }
575
576 static int ag_action_11_proc(void) {
577 int ag_t = (PCB).token_number;
578
579 (PCB).btsx = 0, (PCB).drt = -1;
580 do {
581 (PCB).vs[(PCB).ssx] = *(PCB).lab;
582 (PCB).ssx--;
583 ag_track();
584 ag_ra();
585 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
586 (PCB).ssx++;
587 if ((PCB).rx < (PCB).fx) {
588 (PCB).input_code = (PCB).lab[(PCB).rx++];
589 (PCB).token_number = (t201a_token_type) AG_TCV((PCB).input_code);}
590 else {
591 GET_INPUT;
592 (PCB).lab[(PCB).fx++] = (PCB).input_code;
593 (PCB).token_number = (t201a_token_type) AG_TCV((PCB).input_code);
594 (PCB).rx++;
595 }
596 if (ag_key_index[(PCB).sn]) {
597 unsigned ag_k = ag_key_index[(PCB).sn];
598 int ag_ch = CONVERT_CASE((PCB).input_code);
599 if (ag_ch < 255) {
600 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
601 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
602 }
603 }
604 }
605 while ((PCB).token_number == (t201a_token_type) ag_t);
606 (PCB).rx = 0;
607 return 1;
608 }
609
610 static int ag_action_3_r_proc(void) {
611 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
612 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
613 (PCB).btsx = 0, (PCB).drt = -1;
614 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
615 ag_ra();
616 return (PCB).exit_flag == AG_RUNNING_CODE;
617 }
618
619 static int ag_action_3_s_proc(void) {
620 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
621 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
622 (PCB).btsx = 0, (PCB).drt = -1;
623 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
624 ag_ra();
625 return (PCB).exit_flag == AG_RUNNING_CODE;
626 }
627
628 static int ag_action_4_r_proc(void) {
629 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
630 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
631 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
632 return 1;
633 }
634
635 static int ag_action_2_proc(void) {
636 (PCB).btsx = 0, (PCB).drt = -1;
637 if ((PCB).ssx >= 128) {
638 (PCB).exit_flag = AG_STACK_ERROR_CODE;
639 PARSER_STACK_OVERFLOW;
640 }
641 (PCB).vs[(PCB).ssx] = *(PCB).lab;
642 (PCB).ss[(PCB).ssx] = (PCB).sn;
643 (PCB).ssx++;
644 (PCB).sn = (PCB).ag_ap;
645 ag_track();
646 return 0;
647 }
648
649 static int ag_action_9_proc(void) {
650 if ((PCB).drt == -1) {
651 (PCB).drt=(PCB).token_number;
652 (PCB).dssx=(PCB).ssx;
653 (PCB).dsn=(PCB).sn;
654 }
655 ag_prot();
656 (PCB).vs[(PCB).ssx] = ag_null_value;
657 (PCB).ss[(PCB).ssx] = (PCB).sn;
658 (PCB).ssx++;
659 (PCB).sn = (PCB).ag_ap;
660 (PCB).rx = 0;
661 return (PCB).exit_flag == AG_RUNNING_CODE;
662 }
663
664 static int ag_action_2_r_proc(void) {
665 (PCB).ssx++;
666 (PCB).sn = (PCB).ag_ap;
667 return 0;
668 }
669
670 static int ag_action_7_proc(void) {
671 --(PCB).ssx;
672 (PCB).rx = 0;
673 (PCB).exit_flag = AG_SUCCESS_CODE;
674 return 0;
675 }
676
677 static int ag_action_1_proc(void) {
678 ag_track();
679 (PCB).exit_flag = AG_SUCCESS_CODE;
680 return 0;
681 }
682
683 static int ag_action_1_r_proc(void) {
684 (PCB).exit_flag = AG_SUCCESS_CODE;
685 return 0;
686 }
687
688 static int ag_action_1_s_proc(void) {
689 (PCB).exit_flag = AG_SUCCESS_CODE;
690 return 0;
691 }
692
693 static int ag_action_4_proc(void) {
694 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
695 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
696 (PCB).btsx = 0, (PCB).drt = -1;
697 (PCB).vs[(PCB).ssx] = *(PCB).lab;
698 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
699 else (PCB).ss[(PCB).ssx] = (PCB).sn;
700 ag_track();
701 while ((PCB).exit_flag == AG_RUNNING_CODE) {
702 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
703 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
704 do {
705 unsigned ag_tx = (ag_t1 + ag_t2)/2;
706 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
707 else ag_t2 = ag_tx;
708 } while (ag_t1 < ag_t2);
709 if (ag_tstt[ag_t1] != (PCB).reduction_token) {
710 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE;
711 REDUCTION_TOKEN_ERROR; break;}
712 (PCB).ag_ap = ag_pstt[ag_t1];
713 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
714 }
715 return 0;
716 }
717
718 static int ag_action_3_proc(void) {
719 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
720 (PCB).btsx = 0, (PCB).drt = -1;
721 (PCB).vs[(PCB).ssx] = *(PCB).lab;
722 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
723 else (PCB).ss[(PCB).ssx] = (PCB).sn;
724 ag_track();
725 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
726 ag_ra();
727 while ((PCB).exit_flag == AG_RUNNING_CODE) {
728 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
729 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
730 do {
731 unsigned ag_tx = (ag_t1 + ag_t2)/2;
732 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
733 else ag_t2 = ag_tx;
734 } while (ag_t1 < ag_t2);
735 if (ag_tstt[ag_t1] != (PCB).reduction_token) {
736 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE;
737 REDUCTION_TOKEN_ERROR; break;}
738 (PCB).ag_ap = ag_pstt[ag_t1];
739 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
740 }
741 return 0;
742 }
743
744 static int ag_action_8_proc(void) {
745 ag_undo();
746 (PCB).rx = 0;
747 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
748 ag_diagnose();
749 SYNTAX_ERROR;
750 {(PCB).rx = 1; ag_track();}
751 return (PCB).exit_flag == AG_RUNNING_CODE;
752 }
753
754 static int ag_action_5_proc(void) {
755 int ag_sd = ag_fl[(PCB).ag_ap];
756 (PCB).btsx = 0, (PCB).drt = -1;
757 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
758 else {
759 (PCB).ss[(PCB).ssx] = (PCB).sn;
760 }
761 (PCB).rx = 0;
762 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
763 ag_ra();
764 while ((PCB).exit_flag == AG_RUNNING_CODE) {
765 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
766 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
767 do {
768 unsigned ag_tx = (ag_t1 + ag_t2)/2;
769 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
770 else ag_t2 = ag_tx;
771 } while (ag_t1 < ag_t2);
772 if (ag_tstt[ag_t1] != (PCB).reduction_token) {
773 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE;
774 REDUCTION_TOKEN_ERROR; break;}
775 (PCB).ag_ap = ag_pstt[ag_t1];
776 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
777 }
778 return (PCB).exit_flag == AG_RUNNING_CODE;
779 }
780
781 static int ag_action_6_proc(void) {
782 int ag_sd = ag_fl[(PCB).ag_ap];
783 (PCB).reduction_token = (t201a_token_type) ag_ptt[(PCB).ag_ap];
784 if ((PCB).drt == -1) {
785 (PCB).drt=(PCB).token_number;
786 (PCB).dssx=(PCB).ssx;
787 (PCB).dsn=(PCB).sn;
788 }
789 if (ag_sd) {
790 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
791 }
792 else {
793 ag_prot();
794 (PCB).vs[(PCB).ssx] = ag_null_value;
795 (PCB).ss[(PCB).ssx] = (PCB).sn;
796 }
797 (PCB).rx = 0;
798 while ((PCB).exit_flag == AG_RUNNING_CODE) {
799 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
800 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
801 do {
802 unsigned ag_tx = (ag_t1 + ag_t2)/2;
803 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
804 else ag_t2 = ag_tx;
805 } while (ag_t1 < ag_t2);
806 if (ag_tstt[ag_t1] != (PCB).reduction_token) {
807 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE;
808 REDUCTION_TOKEN_ERROR; break;}
809 (PCB).ag_ap = ag_pstt[ag_t1];
810 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
811 }
812 return (PCB).exit_flag == AG_RUNNING_CODE;
813 }
814
815
816 void init_t201a(void) {
817 (PCB).rx = (PCB).fx = 0;
818 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
819 (PCB).exit_flag = AG_RUNNING_CODE;
820 (PCB).line = FIRST_LINE;
821 (PCB).column = FIRST_COLUMN;
822 (PCB).btsx = 0, (PCB).drt = -1;
823 }
824
825 void t201a(void) {
826 init_t201a();
827 (PCB).exit_flag = AG_RUNNING_CODE;
828 while ((PCB).exit_flag == AG_RUNNING_CODE) {
829 unsigned ag_t1 = ag_sbt[(PCB).sn];
830 if (ag_tstt[ag_t1]) {
831 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
832 if ((PCB).rx < (PCB).fx) {
833 (PCB).input_code = (PCB).lab[(PCB).rx++];
834 (PCB).token_number = (t201a_token_type) AG_TCV((PCB).input_code);}
835 else {
836 GET_INPUT;
837 (PCB).lab[(PCB).fx++] = (PCB).input_code;
838 (PCB).token_number = (t201a_token_type) AG_TCV((PCB).input_code);
839 (PCB).rx++;
840 }
841 if (ag_key_index[(PCB).sn]) {
842 unsigned ag_k = ag_key_index[(PCB).sn];
843 int ag_ch = CONVERT_CASE((PCB).input_code);
844 if (ag_ch < 255) {
845 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
846 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
847 }
848 }
849 do {
850 unsigned ag_tx = (ag_t1 + ag_t2)/2;
851 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
852 ag_t1 = ag_tx + 1;
853 else ag_t2 = ag_tx;
854 } while (ag_t1 < ag_t2);
855 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number)
856 ag_t1 = ag_sbe[(PCB).sn];
857 }
858 (PCB).ag_ap = ag_pstt[ag_t1];
859 (ag_gt_procs_scan[ag_astt[ag_t1]])();
860 }
861 }
862
863
864
865 int main(void) {
866 t201a();
867 return 0;
868 }