comparison tests/agcl/oldagsrc/good/rcalcx.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 AnaGram, a System for Syntax Directed Parsing
3 RCALC.SYN: A Roman Numeral Calculator Example
4
5 Copyright (c) MCMXCIII, MCMXCVI, Parsifal Software.
6 All Rights Reserved.
7 */
8 /*
9 * AnaGram, A System for Syntax Directed Programming
10 * File generated by: ...
11 *
12 * AnaGram Parsing Engine
13 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
14 *
15 * This software is provided 'as-is', without any express or implied
16 * warranty. In no event will the authors be held liable for any damages
17 * arising from the use of this software.
18 *
19 * Permission is granted to anyone to use this software for any purpose,
20 * including commercial applications, and to alter it and redistribute it
21 * freely, subject to the following restrictions:
22 *
23 * 1. The origin of this software must not be misrepresented; you must not
24 * claim that you wrote the original software. If you use this software
25 * in a product, an acknowledgment in the product documentation would be
26 * appreciated but is not required.
27 * 2. Altered source versions must be plainly marked as such, and must not be
28 * misrepresented as being the original software.
29 * 3. This notice may not be removed or altered from any source distribution.
30 */
31
32 #ifndef RCALCX_H
33 #include "rcalcx.h"
34 #endif
35
36 #ifndef RCALCX_H
37 #error Mismatched header file
38 #endif
39
40 #include <ctype.h>
41 #include <stdio.h>
42
43 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
44 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
45 #define CONTEXT ((PCB).cs[(PCB).ssx])
46
47
48 #ifndef PCB_TYPE
49 #define PCB_TYPE rcalcx_pcb_type
50 #endif
51
52
53 #define PCB (*pcb_pointer)
54 #define PCB_DECL PCB_TYPE *pcb_pointer
55 #define PCB_POINTER pcb_pointer
56
57 /* Line -, rcalcx.syn */
58 /* Embedded C */
59 #include <stdio.h>
60
61 #define PCB_TYPE Parser
62
63 class Parser : public rcalcx_pcb_type {
64 int semantic_error;
65 public:
66 Parser() {}
67 void parse(char *);
68 void syntax_error();
69 int divide_error(int cn);
70 void print_roman(long k);
71 };
72
73
74 void Parser::parse(char *text) {
75 pointer = (unsigned char *) text;
76 semantic_error = 0;
77 rcalcx(this);
78 }
79
80 /* Macro Definitions */
81
82 #define GET_CONTEXT CONTEXT = PCB.column
83 #define SYNTAX_ERROR PCB.syntax_error()
84
85 /*
86
87 syntax_error() positions a '^' character under the input line at the
88 point where the syntax error was discovered and then writes the error
89 message.
90
91 */
92
93 void Parser::syntax_error() {
94 int k = column;
95 while (k-- > 0) putchar(' ');
96 printf("^? %s\n","ERRARE HUMANUM EST\n");
97 }
98
99
100 /*
101
102 divide_error() is called when an attempt is made to divide by zero. The
103 entire divisor is marked with '^' characters. "semantic_error" is set
104 in order to disable printing of a result.
105
106 */
107
108 int Parser::divide_error(int cn) {
109 int k = column - cn;
110 while (cn--) putchar(' ');
111 while (k--) putchar('^');
112 puts(" DIVISOR NIHIL EST");
113 semantic_error = 1;
114 return 0;
115 }
116
117
118 /*
119
120 print_roman() prints a signed integer in upper case Roman numerals.
121
122 */
123
124 void Parser::print_roman(long k) {
125 if (semantic_error) {
126 semantic_error = 0;
127 return;
128 }
129 printf(" = ");
130 if (k == 0) {printf("NIHIL\n"); return;}
131
132 if (k < 0) putchar('-'), k=-k;
133
134 while (k >= 1000) putchar('M'), k-=1000;
135
136 if (k >= 900) printf("CM"), k-=900;
137 if (k >= 500) putchar('D'), k-=500;
138 if (k >= 400) printf("CD"), k-=400;
139
140 while (k >= 100) putchar('C'), k-=100;
141
142 if (k >= 90) printf("XC"), k-=90;
143 if (k >= 50) putchar('L'), k-=50;
144 if (k >= 40) printf("XL"), k-=40;
145
146 while (k >= 10) putchar('X'), k-=10;
147
148 if (k >= 9) printf("IX"), k -= 9;
149 if (k >= 5) putchar('V'), k-=5;
150 if (k >= 4) printf("IV"), k-=4;
151
152 while (k >= 1) putchar('I'), k--;
153
154 putchar('\n');
155 }
156
157
158 /* Main Program -- reads a line from stdin and calls parser */
159
160 int main(void) {
161 char line[82];
162 while (1) {
163 Parser pcb;
164 printf("#");
165 if (gets(line) == NULL) break;
166 pcb.parse(line);
167 }
168 return 0;
169 }
170
171
172 #ifndef CONVERT_CASE
173
174 static const char agCaseTable[31] = {
175 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
176 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
177 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0,
178 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
179 };
180
181 static int agConvertCase(int c) {
182 if (c >= 'a' && c <= 'z') return c ^= 0x20;
183 if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0];
184 return c;
185 }
186
187 #define CONVERT_CASE(c) agConvertCase(c)
188
189 #endif
190
191
192 #ifndef TAB_SPACING
193 #define TAB_SPACING 8
194 #endif
195
196 static void ag_rp_1(PCB_DECL, long x) {
197 /* Line -, rcalcx.syn */
198 PCB.print_roman(x);
199 }
200
201 static long ag_rp_2(PCB_DECL, long x, long y) {
202 /* Line -, rcalcx.syn */
203 return x+y;
204 }
205
206 static long ag_rp_3(PCB_DECL, long x, long y) {
207 /* Line -, rcalcx.syn */
208 return x-y;
209 }
210
211 static long ag_rp_4(PCB_DECL, long x, long y) {
212 /* Line -, rcalcx.syn */
213 return x*y;
214 }
215
216 static long ag_rp_5(PCB_DECL, long x, long y) {
217 /* Line -, rcalcx.syn */
218 return y ? x/y : PCB.divide_error(RULE_CONTEXT[2]);
219 }
220
221 static long ag_rp_6(PCB_DECL) {
222 /* Line -, rcalcx.syn */
223 return 0;
224 }
225
226 static long ag_rp_7(PCB_DECL, long x) {
227 /* Line -, rcalcx.syn */
228 return x;
229 }
230
231 static long ag_rp_8(PCB_DECL, long x) {
232 /* Line -, rcalcx.syn */
233 return -x;
234 }
235
236 static long ag_rp_9(PCB_DECL, long x, long y) {
237 /* Line -, rcalcx.syn */
238 return x+y;
239 }
240
241 static long ag_rp_10(PCB_DECL) {
242 /* Line -, rcalcx.syn */
243 return 1000;
244 }
245
246 static long ag_rp_11(PCB_DECL, long x) {
247 /* Line -, rcalcx.syn */
248 return x+1000;
249 }
250
251 static long ag_rp_12(PCB_DECL, long x, long y) {
252 /* Line -, rcalcx.syn */
253 return x+y;
254 }
255
256 static long ag_rp_13(PCB_DECL) {
257 /* Line -, rcalcx.syn */
258 return 900;
259 }
260
261 static long ag_rp_14(PCB_DECL) {
262 /* Line -, rcalcx.syn */
263 return 400;
264 }
265
266 static long ag_rp_15(PCB_DECL) {
267 /* Line -, rcalcx.syn */
268 return 100;
269 }
270
271 static long ag_rp_16(PCB_DECL) {
272 /* Line -, rcalcx.syn */
273 return 500;
274 }
275
276 static long ag_rp_17(PCB_DECL, long x) {
277 /* Line -, rcalcx.syn */
278 return x+100;
279 }
280
281 static long ag_rp_18(PCB_DECL, long x, long y) {
282 /* Line -, rcalcx.syn */
283 return x+y;
284 }
285
286 static long ag_rp_19(PCB_DECL) {
287 /* Line -, rcalcx.syn */
288 return 990;
289 }
290
291 static long ag_rp_20(PCB_DECL) {
292 /* Line -, rcalcx.syn */
293 return 490;
294 }
295
296 static long ag_rp_21(PCB_DECL) {
297 /* Line -, rcalcx.syn */
298 return 90;
299 }
300
301 static long ag_rp_22(PCB_DECL) {
302 /* Line -, rcalcx.syn */
303 return 40;
304 }
305
306 static long ag_rp_23(PCB_DECL) {
307 /* Line -, rcalcx.syn */
308 return 10;
309 }
310
311 static long ag_rp_24(PCB_DECL) {
312 /* Line -, rcalcx.syn */
313 return 50;
314 }
315
316 static long ag_rp_25(PCB_DECL, long x) {
317 /* Line -, rcalcx.syn */
318 return x+10;
319 }
320
321 static long ag_rp_26(PCB_DECL) {
322 /* Line -, rcalcx.syn */
323 return 999;
324 }
325
326 static long ag_rp_27(PCB_DECL) {
327 /* Line -, rcalcx.syn */
328 return 499;
329 }
330
331 static long ag_rp_28(PCB_DECL) {
332 /* Line -, rcalcx.syn */
333 return 99;
334 }
335
336 static long ag_rp_29(PCB_DECL) {
337 /* Line -, rcalcx.syn */
338 return 49;
339 }
340
341 static long ag_rp_30(PCB_DECL) {
342 /* Line -, rcalcx.syn */
343 return 9;
344 }
345
346 static long ag_rp_31(PCB_DECL) {
347 /* Line -, rcalcx.syn */
348 return 4;
349 }
350
351 static long ag_rp_32(PCB_DECL) {
352 /* Line -, rcalcx.syn */
353 return 1;
354 }
355
356 static long ag_rp_33(PCB_DECL) {
357 /* Line -, rcalcx.syn */
358 return 5;
359 }
360
361 static long ag_rp_34(PCB_DECL, long x) {
362 /* Line -, rcalcx.syn */
363 return x+1;
364 }
365
366
367 #define READ_COUNTS
368 #define WRITE_COUNTS
369 #undef V
370 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
371 #undef VS
372 #define VS(i) (PCB).vs[(PCB).ssx + i]
373
374 #ifndef GET_CONTEXT
375 #define GET_CONTEXT CONTEXT = (PCB).input_context
376 #endif
377
378 typedef enum {
379 ag_action_1,
380 ag_action_2,
381 ag_action_3,
382 ag_action_4,
383 ag_action_5,
384 ag_action_6,
385 ag_action_7,
386 ag_action_8,
387 ag_action_9,
388 ag_action_10,
389 ag_action_11,
390 ag_action_12
391 } ag_parser_action;
392
393
394 #ifndef NULL_VALUE_INITIALIZER
395 #define NULL_VALUE_INITIALIZER = { 0 }
396 #endif
397
398 static rcalcx_vs_type const ag_null_value NULL_VALUE_INITIALIZER;
399
400 static const unsigned char ag_rpx[] = {
401 0, 1, 0, 2, 3, 0, 4, 5, 0, 6, 7, 8, 9, 0, 0, 10, 11, 12,
402 0, 0, 13, 14, 0, 15, 16, 17, 18, 0, 0, 19, 20, 21, 22, 0, 23, 24,
403 25, 26, 27, 28, 29, 30, 31, 0, 32, 33, 34
404 };
405
406 static const unsigned char ag_key_itt[] = {
407 0
408 };
409
410 static const unsigned short ag_key_pt[] = {
411 0
412 };
413
414 static const unsigned char ag_key_ch[] = {
415 0, 78,255
416 };
417
418 static const unsigned char ag_key_act[] = {
419 0,3,4
420 };
421
422 static const unsigned char ag_key_parm[] = {
423 0, 38, 0
424 };
425
426 static const unsigned char ag_key_jmp[] = {
427 0, 0, 0
428 };
429
430 static const unsigned char ag_key_index[] = {
431 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1,
432 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
433 };
434
435 static const unsigned char ag_key_ends[] = {
436 73,72,73,76,0,
437 };
438
439 #define AG_TCV(x) ag_tcv[(x)]
440
441 static const unsigned char ag_tcv[] = {
442 5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
443 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
444 0, 0, 0, 0, 40, 39, 35, 33, 0, 34, 0, 36, 0, 0, 0, 0, 0, 0,
445 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 0, 0, 0,
446 0, 28, 0, 0, 26, 17, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 25, 0,
447 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 0, 0, 0, 0, 28, 0, 0,
448 26, 17, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 25, 0, 0, 0, 0, 0,
449 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
450 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
454 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
455 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
456 0, 0, 0, 0
457 };
458
459 #ifndef SYNTAX_ERROR
460 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
461 (PCB).error_message, (PCB).line, (PCB).column)
462 #endif
463
464 #ifndef FIRST_LINE
465 #define FIRST_LINE 1
466 #endif
467
468 #ifndef FIRST_COLUMN
469 #define FIRST_COLUMN 1
470 #endif
471
472 #ifndef PARSER_STACK_OVERFLOW
473 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
474 "\nParser stack overflow, line %d, column %d\n",\
475 (PCB).line, (PCB).column);}
476 #endif
477
478 #ifndef REDUCTION_TOKEN_ERROR
479 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
480 "\nReduction token error, line %d, column %d\n", \
481 (PCB).line, (PCB).column);}
482 #endif
483
484
485 #ifndef INPUT_CODE
486 #define INPUT_CODE(T) (T)
487 #endif
488
489 typedef enum
490 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
491 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
492
493 static void ag_get_key_word(PCB_DECL, int ag_k) {
494 int ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
495 const unsigned char *ag_p;
496 int ag_ch;
497 while (1) {
498 switch (ag_key_act[ag_k]) {
499 case ag_cf_end_key: {
500 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k];
501 do {
502 if ((ag_ch = *sp++) == 0) {
503 int ag_k1 = ag_key_parm[ag_k];
504 int ag_k2 = ag_key_pt[ag_k1];
505 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail;
506 (PCB).token_number = (rcalcx_token_type) ag_key_pt[ag_k1 + 1];
507 return;
508 }
509 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch);
510 goto ag_fail;
511 }
512 case ag_end_key: {
513 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k];
514 do {
515 if ((ag_ch = *sp++) == 0) {
516 (PCB).token_number = (rcalcx_token_type) ag_key_parm[ag_k];
517 return;
518 }
519 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch);
520 }
521 case ag_no_match_key:
522 ag_fail:
523 (PCB).la_ptr = (PCB).pointer + ag_save;
524 return;
525 case ag_cf_set_key: {
526 int ag_k1 = ag_key_parm[ag_k];
527 int ag_k2 = ag_key_pt[ag_k1];
528 ag_k = ag_key_jmp[ag_k];
529 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) break;
530 ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
531 (PCB).token_number = (rcalcx_token_type) ag_key_pt[ag_k1+1];
532 break;
533 }
534 case ag_set_key:
535 ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
536 (PCB).token_number = (rcalcx_token_type) ag_key_parm[ag_k];
537 case ag_jmp_key:
538 ag_k = ag_key_jmp[ag_k];
539 break;
540 case ag_accept_key:
541 (PCB).token_number = (rcalcx_token_type) ag_key_parm[ag_k];
542 return;
543 case ag_cf_accept_key: {
544 int ag_k1 = ag_key_parm[ag_k];
545 int ag_k2 = ag_key_pt[ag_k1];
546 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)])
547 (PCB).la_ptr = (PCB).pointer + ag_save;
548 else (PCB).token_number = (rcalcx_token_type) ag_key_pt[ag_k1+1];
549 return;
550 }
551 }
552 ag_ch = CONVERT_CASE(*(PCB).la_ptr++);
553 ag_p = &ag_key_ch[ag_k];
554 if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++;
555 if (ag_ch > 255 || *ag_p != ag_ch) {
556 (PCB).la_ptr = (PCB).pointer + ag_save;
557 return;
558 }
559 ag_k = (int) (ag_p - ag_key_ch);
560 }
561 }
562
563
564 #ifndef AG_NEWLINE
565 #define AG_NEWLINE 10
566 #endif
567
568 #ifndef AG_RETURN
569 #define AG_RETURN 13
570 #endif
571
572 #ifndef AG_FORMFEED
573 #define AG_FORMFEED 12
574 #endif
575
576 #ifndef AG_TABCHAR
577 #define AG_TABCHAR 9
578 #endif
579
580 static void ag_track(PCB_DECL) {
581 int ag_k = (int) ((PCB).la_ptr - (PCB).pointer);
582 while (ag_k--) {
583 switch (*(PCB).pointer++) {
584 case AG_NEWLINE:
585 (PCB).column = 1, (PCB).line++;
586 case AG_RETURN:
587 case AG_FORMFEED:
588 break;
589 case AG_TABCHAR:
590 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
591 break;
592 default:
593 (PCB).column++;
594 }
595 }
596 }
597
598
599 static void ag_prot(PCB_DECL) {
600 int ag_k;
601 ag_k = 128 - ++(PCB).btsx;
602 if (ag_k <= (PCB).ssx) {
603 (PCB).exit_flag = AG_STACK_ERROR_CODE;
604 PARSER_STACK_OVERFLOW;
605 return;
606 }
607 (PCB).bts[(PCB).btsx] = (PCB).sn;
608 (PCB).bts[ag_k] = (PCB).ssx;
609 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
610 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
611 (PCB).cs[ag_k] = (PCB).cs[(PCB).ssx];
612 }
613
614 static void ag_undo(PCB_DECL) {
615 if ((PCB).drt == -1) return;
616 while ((PCB).btsx) {
617 int ag_k = 128 - (PCB).btsx;
618 (PCB).sn = (PCB).bts[(PCB).btsx--];
619 (PCB).ssx = (PCB).bts[ag_k];
620 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
621 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
622 (PCB).cs[(PCB).ssx] = (PCB).cs[ag_k];
623 }
624 (PCB).token_number = (rcalcx_token_type) (PCB).drt;
625 (PCB).ssx = (PCB).dssx;
626 (PCB).sn = (PCB).dsn;
627 (PCB).drt = -1;
628 }
629
630
631 static const unsigned char ag_tstt[] = {
632 40,38,34,29,28,26,25,21,20,17,1,0,31,32,
633 1,0,
634 40,38,34,29,28,26,25,21,20,17,0,2,3,4,6,8,9,12,13,15,16,18,19,22,23,24,27,
635 30,37,
636 28,0,
637 29,26,25,21,20,17,0,
638 25,0,
639 26,21,20,17,0,
640 29,28,0,24,30,
641 20,0,
642 21,17,0,
643 29,28,26,25,0,19,23,24,27,30,
644 29,28,26,25,21,20,17,0,16,18,19,22,23,24,27,30,
645 40,38,34,29,28,26,25,21,20,17,1,0,31,32,
646 40,38,34,29,28,26,25,21,20,17,1,0,31,32,
647 39,36,35,34,33,5,1,0,31,32,
648 39,36,35,34,33,5,1,0,31,32,
649 40,38,34,29,28,26,25,21,20,17,0,2,8,9,12,13,15,16,18,19,22,23,24,27,30,37,
650 40,38,34,29,28,26,25,21,20,17,0,2,4,6,8,9,12,13,15,16,18,19,22,23,24,27,30,
651 37,
652 36,35,0,10,11,
653 34,33,5,0,7,8,
654 39,34,33,0,7,8,14,
655 40,38,34,29,28,26,25,21,20,17,1,0,31,32,
656 40,38,34,29,28,26,25,21,20,17,0,2,8,9,12,13,15,16,18,19,22,23,24,27,30,37,
657 40,38,34,29,28,26,25,21,20,17,1,0,31,32,
658 40,38,34,29,28,26,25,21,20,17,0,2,8,9,12,13,15,16,18,19,22,23,24,27,30,37,
659 40,38,34,29,28,26,25,21,20,17,0,2,6,8,9,12,13,15,16,18,19,22,23,24,27,30,37,
660 40,38,34,29,28,26,25,21,20,17,1,0,31,32,
661 40,38,34,29,28,26,25,21,20,17,0,2,6,8,9,12,13,15,16,18,19,22,23,24,27,30,37,
662 39,36,35,34,33,5,1,0,31,32,
663 36,35,0,10,11,
664 36,35,0,10,11,
665
666 };
667
668
669 static unsigned const char ag_astt[385] = {
670 8,8,8,8,8,8,8,8,8,8,1,7,1,1,9,5,1,1,1,2,1,2,1,2,1,2,7,1,0,1,1,1,1,2,1,1,1,
671 1,1,1,1,1,1,1,1,10,5,2,2,2,2,2,2,4,10,5,2,2,2,2,4,2,1,5,2,1,10,5,2,2,4,2,1,
672 2,1,5,2,1,2,1,1,2,1,2,1,2,1,10,5,2,1,2,1,1,2,1,1,5,5,5,5,5,5,5,5,5,5,1,7,1,
673 3,5,5,5,5,5,5,5,5,5,5,1,7,1,3,5,5,5,5,5,5,1,7,1,3,5,5,5,5,5,5,1,7,1,3,1,1,
674 1,2,1,2,1,2,1,2,7,2,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,7,1,1,
675 1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,2,7,1,1,1,1,1,7,1,1,2,5,5,5,5,
676 5,5,5,5,5,5,1,7,1,3,1,1,1,2,1,2,1,2,1,2,7,2,1,2,2,1,1,1,1,1,1,1,1,1,1,1,5,
677 5,5,5,5,5,5,5,5,5,1,7,1,3,1,1,1,2,1,2,1,2,1,2,7,2,1,2,2,1,1,1,1,1,1,1,1,1,
678 1,1,1,1,1,2,1,2,1,2,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,5,5,5,
679 5,5,1,7,1,3,1,1,1,2,1,2,1,2,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,
680 5,5,1,7,1,3,1,1,4,1,1,1,1,4,1,1
681 };
682
683
684 static const unsigned char ag_pstt[] = {
685 2,2,2,2,2,2,2,2,2,2,1,0,1,2,
686 48,50,
687 13,14,12,45,4,35,6,24,9,15,2,18,0,19,18,16,18,9,17,11,15,10,15,8,7,15,5,3,
688 15,
689 46,43,
690 42,40,41,38,39,37,44,
691 36,33,
692 32,30,31,29,34,
693 45,4,27,26,3,
694 25,22,
695 21,20,23,
696 45,4,35,6,18,17,7,17,5,3,
697 45,4,35,6,24,9,16,13,12,10,12,8,7,12,5,3,
698 49,49,49,49,49,49,49,49,49,49,1,12,1,52,
699 49,49,49,49,49,49,49,49,49,49,1,13,1,58,
700 49,49,49,49,49,49,1,14,1,56,
701 49,49,49,49,49,49,1,15,1,55,
702 13,14,12,45,4,35,6,24,9,15,16,11,16,11,9,17,11,15,10,15,8,7,15,5,3,15,
703 13,14,12,45,4,35,6,24,9,15,17,18,20,18,16,18,9,17,11,15,10,15,8,7,15,5,3,15,
704 21,23,2,24,22,
705 12,26,1,19,27,25,
706 28,12,26,20,27,25,10,
707 49,49,49,49,49,49,49,49,49,49,1,21,1,54,
708 13,14,12,45,4,35,6,24,9,15,22,7,16,7,9,17,11,15,10,15,8,7,15,5,3,15,
709 49,49,49,49,49,49,49,49,49,49,1,23,1,53,
710 13,14,12,45,4,35,6,24,9,15,24,6,16,6,9,17,11,15,10,15,8,7,15,5,3,15,
711 13,14,12,45,4,35,6,24,9,15,25,29,29,16,29,9,17,11,15,10,15,8,7,15,5,3,15,
712 49,49,49,49,49,49,49,49,49,49,1,26,1,51,
713 13,14,12,45,4,35,6,24,9,15,27,30,30,16,30,9,17,11,15,10,15,8,7,15,5,3,15,
714 49,49,49,49,49,49,1,28,1,57,
715 21,23,4,24,22,
716 21,23,3,24,22,
717
718 };
719
720
721 static const unsigned short ag_sbt[] = {
722 0, 14, 16, 45, 47, 54, 56, 61, 66, 68, 71, 81, 97, 111,
723 125, 135, 145, 171, 199, 204, 210, 217, 231, 257, 271, 297, 324, 338,
724 365, 375, 380, 385
725 };
726
727
728 static const unsigned short ag_sbe[] = {
729 11, 15, 26, 46, 53, 55, 60, 63, 67, 70, 75, 88, 108, 122,
730 132, 142, 155, 181, 201, 207, 213, 228, 241, 268, 281, 307, 335, 348,
731 372, 377, 382, 385
732 };
733
734
735 static const unsigned char ag_fl[] = {
736 2,2,1,3,3,1,3,3,1,1,3,2,2,1,1,1,2,2,1,1,2,2,1,1,1,2,2,1,1,2,2,2,2,1,1,
737 1,2,2,2,2,2,2,2,1,1,1,2,1,2,0,1,2,2,2,2,2,2,2,2
738 };
739
740 static const unsigned char ag_ptt[] = {
741 0, 3, 4, 4, 4, 6, 6, 6, 9, 9, 9, 9, 37, 37, 37, 15, 15, 16,
742 16, 16, 18, 18, 18, 22, 22, 22, 19, 19, 19, 23, 23, 23, 23, 23, 27, 27,
743 27, 24, 24, 24, 24, 24, 24, 24, 30, 30, 30, 31, 31, 32, 32, 7, 8, 10,
744 11, 2, 12, 14, 13
745 };
746
747
748 static void ag_ra(PCB_DECL)
749 {
750 switch(ag_rpx[(PCB).ag_ap]) {
751 case 1: ag_rp_1(PCB_POINTER, V(0,(long *))); break;
752 case 2: V(0,(long *)) = ag_rp_2(PCB_POINTER, V(0,(long *)), V(2,(long *))); break;
753 case 3: V(0,(long *)) = ag_rp_3(PCB_POINTER, V(0,(long *)), V(2,(long *))); break;
754 case 4: V(0,(long *)) = ag_rp_4(PCB_POINTER, V(0,(long *)), V(2,(long *))); break;
755 case 5: V(0,(long *)) = ag_rp_5(PCB_POINTER, V(0,(long *)), V(2,(long *))); break;
756 case 6: V(0,(long *)) = ag_rp_6(PCB_POINTER); break;
757 case 7: V(0,(long *)) = ag_rp_7(PCB_POINTER, V(1,(long *))); break;
758 case 8: V(0,(long *)) = ag_rp_8(PCB_POINTER, V(1,(long *))); break;
759 case 9: V(0,(long *)) = ag_rp_9(PCB_POINTER, V(0,(long *)), V(1,(long *))); break;
760 case 10: V(0,(long *)) = ag_rp_10(PCB_POINTER); break;
761 case 11: V(0,(long *)) = ag_rp_11(PCB_POINTER, V(0,(long *))); break;
762 case 12: V(0,(long *)) = ag_rp_12(PCB_POINTER, V(0,(long *)), V(1,(long *))); break;
763 case 13: V(0,(long *)) = ag_rp_13(PCB_POINTER); break;
764 case 14: V(0,(long *)) = ag_rp_14(PCB_POINTER); break;
765 case 15: V(0,(long *)) = ag_rp_15(PCB_POINTER); break;
766 case 16: V(0,(long *)) = ag_rp_16(PCB_POINTER); break;
767 case 17: V(0,(long *)) = ag_rp_17(PCB_POINTER, V(0,(long *))); break;
768 case 18: V(0,(long *)) = ag_rp_18(PCB_POINTER, V(0,(long *)), V(1,(long *))); break;
769 case 19: V(0,(long *)) = ag_rp_19(PCB_POINTER); break;
770 case 20: V(0,(long *)) = ag_rp_20(PCB_POINTER); break;
771 case 21: V(0,(long *)) = ag_rp_21(PCB_POINTER); break;
772 case 22: V(0,(long *)) = ag_rp_22(PCB_POINTER); break;
773 case 23: V(0,(long *)) = ag_rp_23(PCB_POINTER); break;
774 case 24: V(0,(long *)) = ag_rp_24(PCB_POINTER); break;
775 case 25: V(0,(long *)) = ag_rp_25(PCB_POINTER, V(0,(long *))); break;
776 case 26: V(0,(long *)) = ag_rp_26(PCB_POINTER); break;
777 case 27: V(0,(long *)) = ag_rp_27(PCB_POINTER); break;
778 case 28: V(0,(long *)) = ag_rp_28(PCB_POINTER); break;
779 case 29: V(0,(long *)) = ag_rp_29(PCB_POINTER); break;
780 case 30: V(0,(long *)) = ag_rp_30(PCB_POINTER); break;
781 case 31: V(0,(long *)) = ag_rp_31(PCB_POINTER); break;
782 case 32: V(0,(long *)) = ag_rp_32(PCB_POINTER); break;
783 case 33: V(0,(long *)) = ag_rp_33(PCB_POINTER); break;
784 case 34: V(0,(long *)) = ag_rp_34(PCB_POINTER, V(0,(long *))); break;
785 }
786 (PCB).la_ptr = (PCB).pointer;
787 }
788
789 #define TOKEN_NAMES rcalcx_token_names
790 const char *const rcalcx_token_names[41] = {
791 "calculation",
792 "ws",
793 "roman numeral",
794 "calculation",
795 "expression",
796 "eof",
797 "term",
798 "'+'",
799 "'-'",
800 "factor",
801 "'*'",
802 "'/'",
803 "\"NIHIL\"",
804 "'('",
805 "')'",
806 "thousands",
807 "hundreds",
808 "m",
809 "hundreds field",
810 "tens",
811 "c",
812 "d",
813 "count hundreds",
814 "tens field",
815 "units",
816 "x",
817 "l",
818 "count tens",
819 "i",
820 "v",
821 "count units",
822 "",
823 "",
824 "'+'",
825 "'-'",
826 "'*'",
827 "'/'",
828 "roman numeral",
829 "\"NIHIL\"",
830 "')'",
831 "'('",
832
833 };
834
835 #ifndef MISSING_FORMAT
836 #define MISSING_FORMAT "Missing %s"
837 #endif
838 #ifndef UNEXPECTED_FORMAT
839 #define UNEXPECTED_FORMAT "Unexpected %s"
840 #endif
841 #ifndef UNNAMED_TOKEN
842 #define UNNAMED_TOKEN "input"
843 #endif
844
845
846 static void ag_diagnose(PCB_DECL) {
847 int ag_snd = (PCB).sn;
848 int ag_k = ag_sbt[ag_snd];
849
850 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) {
851 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
852 }
853 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8
854 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1
855 && *TOKEN_NAMES[ag_tstt[ag_k]]) {
856 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
857 }
858 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
859 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]);
860 }
861 else if (isprint(INPUT_CODE((*(PCB).pointer))) && INPUT_CODE((*(PCB).pointer)) != '\\') {
862 char buf[20];
863 sprintf(buf, "\'%c\'", (char) INPUT_CODE((*(PCB).pointer)));
864 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf);
865 }
866 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN);
867 (PCB).error_message = (PCB).ag_msg;
868
869
870 }
871 static int ag_action_1_r_proc(PCB_DECL);
872 static int ag_action_2_r_proc(PCB_DECL);
873 static int ag_action_3_r_proc(PCB_DECL);
874 static int ag_action_4_r_proc(PCB_DECL);
875 static int ag_action_1_s_proc(PCB_DECL);
876 static int ag_action_3_s_proc(PCB_DECL);
877 static int ag_action_1_proc(PCB_DECL);
878 static int ag_action_2_proc(PCB_DECL);
879 static int ag_action_3_proc(PCB_DECL);
880 static int ag_action_4_proc(PCB_DECL);
881 static int ag_action_5_proc(PCB_DECL);
882 static int ag_action_6_proc(PCB_DECL);
883 static int ag_action_7_proc(PCB_DECL);
884 static int ag_action_8_proc(PCB_DECL);
885 static int ag_action_9_proc(PCB_DECL);
886 static int ag_action_10_proc(PCB_DECL);
887 static int ag_action_11_proc(PCB_DECL);
888 static int ag_action_8_proc(PCB_DECL);
889
890
891 static int (*const ag_r_procs_scan[])(PCB_DECL) = {
892 ag_action_1_r_proc,
893 ag_action_2_r_proc,
894 ag_action_3_r_proc,
895 ag_action_4_r_proc
896 };
897
898 static int (*const ag_s_procs_scan[])(PCB_DECL) = {
899 ag_action_1_s_proc,
900 ag_action_2_r_proc,
901 ag_action_3_s_proc,
902 ag_action_4_r_proc
903 };
904
905 static int (*const ag_gt_procs_scan[])(PCB_DECL) = {
906 ag_action_1_proc,
907 ag_action_2_proc,
908 ag_action_3_proc,
909 ag_action_4_proc,
910 ag_action_5_proc,
911 ag_action_6_proc,
912 ag_action_7_proc,
913 ag_action_8_proc,
914 ag_action_9_proc,
915 ag_action_10_proc,
916 ag_action_11_proc,
917 ag_action_8_proc
918 };
919
920
921 static int ag_action_10_proc(PCB_DECL) {
922 int ag_t = (PCB).token_number;
923 (PCB).btsx = 0, (PCB).drt = -1;
924 do {
925 ag_track(PCB_POINTER);
926 (PCB).token_number = (rcalcx_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
927 (PCB).la_ptr++;
928 if (ag_key_index[(PCB).sn]) {
929 unsigned ag_k = ag_key_index[(PCB).sn];
930 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
931 if (ag_ch <= 255) {
932 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
933 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word((PCB_TYPE *)PCB_POINTER, ag_k);
934 }
935 }
936 } while ((PCB).token_number == (rcalcx_token_type) ag_t);
937 (PCB).la_ptr = (PCB).pointer;
938 return 1;
939 }
940
941 static int ag_action_11_proc(PCB_DECL) {
942 int ag_t = (PCB).token_number;
943
944 (PCB).btsx = 0, (PCB).drt = -1;
945 do {
946 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
947 (PCB).ssx--;
948 ag_track(PCB_POINTER);
949 ag_ra(PCB_POINTER);
950 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
951 (PCB).ssx++;
952 (PCB).token_number = (rcalcx_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
953 (PCB).la_ptr++;
954 if (ag_key_index[(PCB).sn]) {
955 unsigned ag_k = ag_key_index[(PCB).sn];
956 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
957 if (ag_ch <= 255) {
958 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
959 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word((PCB_TYPE *)PCB_POINTER, ag_k);
960 }
961 }
962 }
963 while ((PCB).token_number == (rcalcx_token_type) ag_t);
964 (PCB).la_ptr = (PCB).pointer;
965 return 1;
966 }
967
968 static int ag_action_3_r_proc(PCB_DECL) {
969 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
970 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
971 (PCB).btsx = 0, (PCB).drt = -1;
972 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
973 ag_ra(PCB_POINTER);
974 return (PCB).exit_flag == AG_RUNNING_CODE;
975 }
976
977 static int ag_action_3_s_proc(PCB_DECL) {
978 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
979 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
980 (PCB).btsx = 0, (PCB).drt = -1;
981 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
982 ag_ra(PCB_POINTER);
983 return (PCB).exit_flag == AG_RUNNING_CODE;
984 }
985
986 static int ag_action_4_r_proc(PCB_DECL) {
987 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
988 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
989 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
990 return 1;
991 }
992
993 static int ag_action_2_proc(PCB_DECL) {
994 (PCB).btsx = 0, (PCB).drt = -1;
995 if ((PCB).ssx >= 128) {
996 (PCB).exit_flag = AG_STACK_ERROR_CODE;
997 PARSER_STACK_OVERFLOW;
998 }
999 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
1000 GET_CONTEXT;
1001 (PCB).ss[(PCB).ssx] = (PCB).sn;
1002 (PCB).ssx++;
1003 (PCB).sn = (PCB).ag_ap;
1004 ag_track(PCB_POINTER);
1005 return 0;
1006 }
1007
1008 static int ag_action_9_proc(PCB_DECL) {
1009 if ((PCB).drt == -1) {
1010 (PCB).drt=(PCB).token_number;
1011 (PCB).dssx=(PCB).ssx;
1012 (PCB).dsn=(PCB).sn;
1013 }
1014 ag_prot(PCB_POINTER);
1015 (PCB).vs[(PCB).ssx] = ag_null_value;
1016 GET_CONTEXT;
1017 (PCB).ss[(PCB).ssx] = (PCB).sn;
1018 (PCB).ssx++;
1019 (PCB).sn = (PCB).ag_ap;
1020 (PCB).la_ptr = (PCB).pointer;
1021 return (PCB).exit_flag == AG_RUNNING_CODE;
1022 }
1023
1024 static int ag_action_2_r_proc(PCB_DECL) {
1025 (PCB).ssx++;
1026 (PCB).sn = (PCB).ag_ap;
1027 return 0;
1028 }
1029
1030 static int ag_action_7_proc(PCB_DECL) {
1031 --(PCB).ssx;
1032 (PCB).la_ptr = (PCB).pointer;
1033 (PCB).exit_flag = AG_SUCCESS_CODE;
1034 return 0;
1035 }
1036
1037 static int ag_action_1_proc(PCB_DECL) {
1038 ag_track(PCB_POINTER);
1039 (PCB).exit_flag = AG_SUCCESS_CODE;
1040 return 0;
1041 }
1042
1043 static int ag_action_1_r_proc(PCB_DECL) {
1044 (PCB).exit_flag = AG_SUCCESS_CODE;
1045 return 0;
1046 }
1047
1048 static int ag_action_1_s_proc(PCB_DECL) {
1049 (PCB).exit_flag = AG_SUCCESS_CODE;
1050 return 0;
1051 }
1052
1053 static int ag_action_4_proc(PCB_DECL) {
1054 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1055 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
1056 (PCB).btsx = 0, (PCB).drt = -1;
1057 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
1058 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1059 else GET_CONTEXT;
1060 (PCB).ss[(PCB).ssx] = (PCB).sn;
1061 ag_track(PCB_POINTER);
1062 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1063 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1064 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1065 do {
1066 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1067 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1068 else ag_t2 = ag_tx;
1069 } while (ag_t1 < ag_t2);
1070 (PCB).ag_ap = ag_pstt[ag_t1];
1071 if ((ag_s_procs_scan[ag_astt[ag_t1]])(PCB_POINTER) == 0) break;
1072 }
1073 return 0;
1074 }
1075
1076 static int ag_action_3_proc(PCB_DECL) {
1077 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1078 (PCB).btsx = 0, (PCB).drt = -1;
1079 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
1080 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1081 else GET_CONTEXT;
1082 (PCB).ss[(PCB).ssx] = (PCB).sn;
1083 ag_track(PCB_POINTER);
1084 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
1085 ag_ra(PCB_POINTER);
1086 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1087 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1088 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1089 do {
1090 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1091 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1092 else ag_t2 = ag_tx;
1093 } while (ag_t1 < ag_t2);
1094 (PCB).ag_ap = ag_pstt[ag_t1];
1095 if ((ag_s_procs_scan[ag_astt[ag_t1]])(PCB_POINTER) == 0) break;
1096 }
1097 return 0;
1098 }
1099
1100 static int ag_action_8_proc(PCB_DECL) {
1101 ag_undo(PCB_POINTER);
1102 (PCB).la_ptr = (PCB).pointer;
1103 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
1104 ag_diagnose(PCB_POINTER);
1105 SYNTAX_ERROR;
1106 {(PCB).la_ptr = (PCB).pointer + 1; ag_track(PCB_POINTER);}
1107 return (PCB).exit_flag == AG_RUNNING_CODE;
1108 }
1109
1110 static int ag_action_5_proc(PCB_DECL) {
1111 int ag_sd = ag_fl[(PCB).ag_ap];
1112 (PCB).btsx = 0, (PCB).drt = -1;
1113 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1114 else {
1115 GET_CONTEXT;
1116 (PCB).ss[(PCB).ssx] = (PCB).sn;
1117 }
1118 (PCB).la_ptr = (PCB).pointer;
1119 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
1120 ag_ra(PCB_POINTER);
1121 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1122 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1123 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1124 do {
1125 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1126 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1127 else ag_t2 = ag_tx;
1128 } while (ag_t1 < ag_t2);
1129 (PCB).ag_ap = ag_pstt[ag_t1];
1130 if ((ag_r_procs_scan[ag_astt[ag_t1]])(PCB_POINTER) == 0) break;
1131 }
1132 return (PCB).exit_flag == AG_RUNNING_CODE;
1133 }
1134
1135 static int ag_action_6_proc(PCB_DECL) {
1136 int ag_sd = ag_fl[(PCB).ag_ap];
1137 (PCB).reduction_token = (rcalcx_token_type) ag_ptt[(PCB).ag_ap];
1138 if ((PCB).drt == -1) {
1139 (PCB).drt=(PCB).token_number;
1140 (PCB).dssx=(PCB).ssx;
1141 (PCB).dsn=(PCB).sn;
1142 }
1143 if (ag_sd) {
1144 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1145 }
1146 else {
1147 ag_prot(PCB_POINTER);
1148 (PCB).vs[(PCB).ssx] = ag_null_value;
1149 GET_CONTEXT;
1150 (PCB).ss[(PCB).ssx] = (PCB).sn;
1151 }
1152 (PCB).la_ptr = (PCB).pointer;
1153 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1154 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1155 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1156 do {
1157 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1158 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1159 else ag_t2 = ag_tx;
1160 } while (ag_t1 < ag_t2);
1161 (PCB).ag_ap = ag_pstt[ag_t1];
1162 if ((ag_r_procs_scan[ag_astt[ag_t1]])(PCB_POINTER) == 0) break;
1163 }
1164 return (PCB).exit_flag == AG_RUNNING_CODE;
1165 }
1166
1167
1168 void init_rcalcx(rcalcx_pcb_type *PCB_POINTER) {
1169 (PCB).la_ptr = (PCB).pointer;
1170 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
1171 (PCB).exit_flag = AG_RUNNING_CODE;
1172 (PCB).line = FIRST_LINE;
1173 (PCB).column = FIRST_COLUMN;
1174 (PCB).btsx = 0, (PCB).drt = -1;
1175 }
1176
1177 void rcalcx(rcalcx_pcb_type *PCB_POINTER) {
1178 init_rcalcx(PCB_POINTER);
1179 (PCB).exit_flag = AG_RUNNING_CODE;
1180 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1181 unsigned ag_t1 = ag_sbt[(PCB).sn];
1182 if (ag_tstt[ag_t1]) {
1183 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
1184 (PCB).token_number = (rcalcx_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
1185 (PCB).la_ptr++;
1186 if (ag_key_index[(PCB).sn]) {
1187 unsigned ag_k = ag_key_index[(PCB).sn];
1188 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
1189 if (ag_ch <= 255) {
1190 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1191 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word((PCB_TYPE *)PCB_POINTER, ag_k);
1192 }
1193 }
1194 do {
1195 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1196 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
1197 ag_t1 = ag_tx + 1;
1198 else ag_t2 = ag_tx;
1199 } while (ag_t1 < ag_t2);
1200 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number)
1201 ag_t1 = ag_sbe[(PCB).sn];
1202 }
1203 (PCB).ag_ap = ag_pstt[ag_t1];
1204 (ag_gt_procs_scan[ag_astt[ag_t1]])((PCB_TYPE *)PCB_POINTER);
1205 }
1206 }
1207
1208