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