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