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