Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/oldagsrc/good/cf.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 Syntax Analyzer. | |
3 Copyright (c) Parsifal Software, 1993-1999. | |
4 All Rights Reserved. | |
5 | |
6 Configuration file module | |
7 */ | |
8 | |
9 //#define INCLUDE_LOGGING | |
10 | |
11 #include "arrays.h" //ARRAYS | |
12 #include "assert.h" //ASSERT | |
13 #include "cint.h" | |
14 #include "config.h" | |
15 #include "data.h" //DATA | |
16 #include "error.h" | |
17 #include "log.hpp" | |
18 #include "myalloc.h" //MYALLOC | |
19 #include "pf.h" //PF | |
20 #include "tfile.h" //TFILE | |
21 #include <ctype.h> //CTYPE | |
22 #include <stdlib.h> //STDLIB | |
23 #include <string.h> //STRING | |
24 | |
25 #undef MODULE | |
26 #define MODULE 50 | |
27 | |
28 /* | |
29 * AnaGram, A System for Syntax Directed Programming | |
30 * File generated by: ... | |
31 * | |
32 * AnaGram Parsing Engine | |
33 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
34 * | |
35 * This software is provided 'as-is', without any express or implied | |
36 * warranty. In no event will the authors be held liable for any damages | |
37 * arising from the use of this software. | |
38 * | |
39 * Permission is granted to anyone to use this software for any purpose, | |
40 * including commercial applications, and to alter it and redistribute it | |
41 * freely, subject to the following restrictions: | |
42 * | |
43 * 1. The origin of this software must not be misrepresented; you must not | |
44 * claim that you wrote the original software. If you use this software | |
45 * in a product, an acknowledgment in the product documentation would be | |
46 * appreciated but is not required. | |
47 * 2. Altered source versions must be plainly marked as such, and must not be | |
48 * misrepresented as being the original software. | |
49 * 3. This notice may not be removed or altered from any source distribution. | |
50 */ | |
51 | |
52 #ifndef CF_H | |
53 #include "cf.h" | |
54 #endif | |
55 | |
56 #ifndef CF_H | |
57 #error Mismatched header file | |
58 #endif | |
59 | |
60 #include <ctype.h> | |
61 #include <stdio.h> | |
62 | |
63 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
64 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
65 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
66 | |
67 | |
68 #define CHANGE_REDUCTION(x) cf_change_reduction(cf_##x##_token) | |
69 int cf_change_reduction(cf_token_type); | |
70 | |
71 | |
72 int cf_value(void); | |
73 | |
74 #define TOKEN_NAMES cf_token_names | |
75 const char *const cf_token_names[104] = { | |
76 "config file", | |
77 "config file", | |
78 "equals", | |
79 "'='", | |
80 "", | |
81 "", | |
82 "minus", | |
83 "'-'", | |
84 "plus", | |
85 "'+'", | |
86 "tilde", | |
87 "'~'", | |
88 "", | |
89 "'('", | |
90 "", | |
91 "')'", | |
92 "blank", | |
93 "", | |
94 "", | |
95 "global parameter", | |
96 "end of line", | |
97 "", | |
98 "", | |
99 "", | |
100 "eof", | |
101 "name", | |
102 "data type", | |
103 "keyword string", | |
104 "number", | |
105 "abstract declarator", | |
106 "", | |
107 "direct abstract declarator", | |
108 "", | |
109 "", | |
110 "star", | |
111 "'*'", | |
112 "", | |
113 "letter", | |
114 "", | |
115 "blank char", | |
116 "c comment", | |
117 "continuation", | |
118 "comment", | |
119 "", | |
120 "carriage return", | |
121 "", | |
122 "newline", | |
123 "white", | |
124 "vertical space", | |
125 "\"//\"", | |
126 "", | |
127 "", | |
128 "", | |
129 "decimal number", | |
130 "", | |
131 "", | |
132 "octal number", | |
133 "'0'", | |
134 "", | |
135 "hex number", | |
136 "\"0x\"", | |
137 "\"0X\"", | |
138 "", | |
139 "simple number", | |
140 "", | |
141 "", | |
142 "keyword string head", | |
143 "string", | |
144 "double quote", | |
145 "", | |
146 "", | |
147 "", | |
148 "string char", | |
149 "simple string char", | |
150 "", | |
151 "\"\\\\a\"", | |
152 "\"\\\\b\"", | |
153 "\"\\\\f\"", | |
154 "\"\\\\n\"", | |
155 "\"\\\\r\"", | |
156 "\"\\\\t\"", | |
157 "\"\\\\v\"", | |
158 "\"\\\\\\\\\"", | |
159 "\"\\\\?\"", | |
160 "\"\\\\\\'\"", | |
161 "\"\\\\\\\"\"", | |
162 "", | |
163 "", | |
164 "backslash", | |
165 "", | |
166 "", | |
167 "", | |
168 "", | |
169 "\"\\\\x\"", | |
170 "any digit", | |
171 "nonoctal digit", | |
172 "", | |
173 "\"*/\"", | |
174 "\"/*\"", | |
175 "", | |
176 "", | |
177 "", | |
178 "", | |
179 "", | |
180 | |
181 }; | |
182 | |
183 | |
184 #line - "cf.syn" | |
185 #define PARSER_STACK_OVERFLOW assert(0) | |
186 #define REDUCTION_TOKEN_ERROR assert(0) | |
187 #define SYNTAX_ERROR cf_syn_error() | |
188 #define GET_CONTEXT CONTEXT.x = PCB.column, CONTEXT.y = PCB.line | |
189 | |
190 static void cf_error(const char *); | |
191 | |
192 class CfErrorHandler : public ConfigParam::ErrorHandler { | |
193 void badParam(const char *s){cf_error(s);} | |
194 } cfErrorHandler; | |
195 | |
196 | |
197 | |
198 static cf_pcb_type cfcb; | |
199 #define PCB cfcb | |
200 | |
201 extern unsigned char *input_base; | |
202 | |
203 static AgString config_file; | |
204 | |
205 void read_config(const AgString path) { | |
206 LOGSECTION("read_config"); | |
207 LOGV(path); | |
208 config_file = path.lastCut(PATH_DELIMITER).leftI().concat("AnaGram.cfg"); | |
209 text_file tf(config_file); | |
210 cfcb.pointer = input_base = (unsigned char *) tf; | |
211 if (input_base) cf(); | |
212 config_file = "AnaGram.cfg"; | |
213 tf = text_file(config_file); | |
214 cfcb.pointer = input_base = (unsigned char *) tf; | |
215 LOGS("Starting parse"); | |
216 if (input_base) cf(); | |
217 } | |
218 | |
219 static void cf_error(const char *msg) { | |
220 errorList.push(Error(config_file, msg, 1)); | |
221 } | |
222 | |
223 Error::Error(AgString f, AgString msg, int contextFlag) | |
224 : file(f), | |
225 line(contextFlag? ERROR_CONTEXT.y : PCB.line), | |
226 column(contextFlag? ERROR_CONTEXT.y :PCB.column), | |
227 key(warn), | |
228 message(msg) | |
229 { | |
230 // Nothing here | |
231 } | |
232 | |
233 | |
234 static void cf_syn_error(void) { | |
235 reset_stk(); | |
236 cf_error(PCB.error_message); | |
237 } | |
238 | |
239 | |
240 int allow_macros = 1; | |
241 int auto_init = 1; | |
242 int auto_resynch = 0; | |
243 int backtrack = 1; | |
244 int bottom_margin = 3; | |
245 int bright_background = 1; | |
246 | |
247 int case_sensitive = 1; | |
248 AgString compile_command(""); | |
249 int const_data = 1; | |
250 AgString context_type; | |
251 AgString coverage_file_name("#.nrc"); | |
252 | |
253 int declare_pcb = 1; | |
254 int default_input_type; | |
255 int default_token_type; | |
256 int default_reductions = 1; | |
257 int diagnose_errors = 1; | |
258 int distinguish_lexemes = 0; | |
259 | |
260 AgString edit_command("ed #.syn"); | |
261 int enable_mouse = 1; | |
262 AgString enum_constant_name("$_%_token"); | |
263 int error_frame = 0; | |
264 int error_trace = 0; | |
265 int escape_backslashes = 0; | |
266 int event_driven = 0; | |
267 | |
268 int far_tables = 0; | |
269 | |
270 int grammar_token = 0; | |
271 AgString header_file_name("#.h"); | |
272 int input_values = 0; | |
273 int iso_latin_1 = 1; | |
274 | |
275 int line_length = 80; | |
276 int line_numbers = 0; | |
277 AgString line_numbers_path; | |
278 int lines_and_columns = 1; | |
279 | |
280 int main_program = 1; | |
281 int max_conflicts = 50; | |
282 //AgString mutex_type; | |
283 | |
284 int near_functions = 0; | |
285 int nest_comments = 0; | |
286 | |
287 int old_style = 0; | |
288 | |
289 int page_length = 66; | |
290 AgString parser_file_name("#.c"); | |
291 AgString parser_name("#"); | |
292 int parser_stack_alignment; | |
293 int parser_stack_size = 32; | |
294 int pointer_input = 0; | |
295 AgString pointer_type("unsigned char *"); | |
296 AgString print_file_name("LPT1"); | |
297 | |
298 int quick_reference = 0; | |
299 | |
300 int reduction_choices =0; | |
301 int reentrant_parser = 0; | |
302 int rule_coverage = 0; | |
303 | |
304 int tab_spacing = 8; | |
305 int test_file_binary = 0; | |
306 AgString test_file_mask("*.*"); | |
307 int test_range = 1; | |
308 int token_names = 0; | |
309 int top_margin = 3; | |
310 int traditional_engine = 0; | |
311 | |
312 int video_mode = -1; | |
313 | |
314 int trial_copy_code = 0; | |
315 | |
316 int error_token; | |
317 int eof_token = 0; | |
318 | |
319 #line - "cf.cpp" | |
320 | |
321 #ifndef CONVERT_CASE | |
322 #define CONVERT_CASE(c) (c) | |
323 #endif | |
324 #ifndef TAB_SPACING | |
325 #define TAB_SPACING 8 | |
326 #endif | |
327 int cf_value(void) { | |
328 int returnValue; | |
329 returnValue = (PCB).vs[(PCB).ssx]; | |
330 return returnValue; | |
331 } | |
332 | |
333 static void ag_rp_1(void) { | |
334 #line - "cf.syn" | |
335 ConfigParam::set(1, cfErrorHandler); | |
336 #line - "cf.cpp" | |
337 } | |
338 | |
339 static void ag_rp_2(void) { | |
340 #line - "cf.syn" | |
341 ConfigParam::set(0, cfErrorHandler); | |
342 #line - "cf.cpp" | |
343 } | |
344 | |
345 static void ag_rp_3(void) { | |
346 #line - "cf.syn" | |
347 ConfigParam::set(cfErrorHandler); | |
348 #line - "cf.cpp" | |
349 } | |
350 | |
351 static void ag_rp_4(void) { | |
352 #line - "cf.syn" | |
353 ConfigParam::set(cfErrorHandler); | |
354 #line - "cf.cpp" | |
355 } | |
356 | |
357 static void ag_rp_5(int n) { | |
358 #line - "cf.syn" | |
359 ConfigParam::set(cfErrorHandler); | |
360 #line - "cf.cpp" | |
361 } | |
362 | |
363 static void ag_rp_6(void) { | |
364 #line - "cf.syn" | |
365 concat_string(); | |
366 #line - "cf.cpp" | |
367 } | |
368 | |
369 static void ag_rp_7(void) { | |
370 #line - "cf.syn" | |
371 concat_string(); | |
372 #line - "cf.cpp" | |
373 } | |
374 | |
375 static int ag_rp_8(void) { | |
376 #line - "cf.syn" | |
377 return scs('('),0; | |
378 #line - "cf.cpp" | |
379 } | |
380 | |
381 static void ag_rp_9(void) { | |
382 #line - "cf.syn" | |
383 concat_string(), acs(')'); | |
384 #line - "cf.cpp" | |
385 } | |
386 | |
387 static void ag_rp_10(void) { | |
388 #line - "cf.syn" | |
389 concat_string(); | |
390 #line - "cf.cpp" | |
391 } | |
392 | |
393 static void ag_rp_11(void) { | |
394 #line - "cf.syn" | |
395 sss(" *"); | |
396 #line - "cf.cpp" | |
397 } | |
398 | |
399 static void ag_rp_12(void) { | |
400 #line - "cf.syn" | |
401 concat_string(); | |
402 #line - "cf.cpp" | |
403 } | |
404 | |
405 static void ag_rp_13(int a) { | |
406 #line - "cf.syn" | |
407 scs(a); | |
408 #line - "cf.cpp" | |
409 } | |
410 | |
411 static void ag_rp_14(int a) { | |
412 #line - "cf.syn" | |
413 acs(a); | |
414 #line - "cf.cpp" | |
415 } | |
416 | |
417 static void ag_rp_15(int a) { | |
418 #line - "cf.syn" | |
419 acs(' '), acs(a); | |
420 #line - "cf.cpp" | |
421 } | |
422 | |
423 static int ag_rp_16(int d) { | |
424 #line - "cf.syn" | |
425 return d - '0'; | |
426 #line - "cf.cpp" | |
427 } | |
428 | |
429 static int ag_rp_17(int n, int d) { | |
430 #line - "cf.syn" | |
431 return 10*n + d - '0'; | |
432 #line - "cf.cpp" | |
433 } | |
434 | |
435 static int ag_rp_18(void) { | |
436 #line - "cf.syn" | |
437 return 0; | |
438 #line - "cf.cpp" | |
439 } | |
440 | |
441 static int ag_rp_19(int n, int d) { | |
442 #line - "cf.syn" | |
443 return 8*n + d - '0'; | |
444 #line - "cf.cpp" | |
445 } | |
446 | |
447 static int ag_rp_20(void) { | |
448 #line - "cf.syn" | |
449 return 0; | |
450 #line - "cf.cpp" | |
451 } | |
452 | |
453 static int ag_rp_21(void) { | |
454 #line - "cf.syn" | |
455 return 0; | |
456 #line - "cf.cpp" | |
457 } | |
458 | |
459 static int ag_rp_22(int n, int d) { | |
460 #line - "cf.syn" | |
461 return 16*n + d - '0'; | |
462 #line - "cf.cpp" | |
463 } | |
464 | |
465 static int ag_rp_23(int n, int d) { | |
466 #line - "cf.syn" | |
467 return 16*n + (d&7) + 9; | |
468 #line - "cf.cpp" | |
469 } | |
470 | |
471 static int ag_rp_24(int s, int n) { | |
472 #line - "cf.syn" | |
473 return s*n; | |
474 #line - "cf.cpp" | |
475 } | |
476 | |
477 static int ag_rp_25(void) { | |
478 #line - "cf.syn" | |
479 return 1; | |
480 #line - "cf.cpp" | |
481 } | |
482 | |
483 static int ag_rp_26(void) { | |
484 #line - "cf.syn" | |
485 return -1; | |
486 #line - "cf.cpp" | |
487 } | |
488 | |
489 static void ag_rp_27(void) { | |
490 #line - "cf.syn" | |
491 ics(); | |
492 #line - "cf.cpp" | |
493 } | |
494 | |
495 static int ag_rp_28(void) { | |
496 #line - "cf.syn" | |
497 return '\a'; | |
498 #line - "cf.cpp" | |
499 } | |
500 | |
501 static int ag_rp_29(void) { | |
502 #line - "cf.syn" | |
503 return '\b'; | |
504 #line - "cf.cpp" | |
505 } | |
506 | |
507 static int ag_rp_30(void) { | |
508 #line - "cf.syn" | |
509 return '\f'; | |
510 #line - "cf.cpp" | |
511 } | |
512 | |
513 static int ag_rp_31(void) { | |
514 #line - "cf.syn" | |
515 return '\n'; | |
516 #line - "cf.cpp" | |
517 } | |
518 | |
519 static int ag_rp_32(void) { | |
520 #line - "cf.syn" | |
521 return '\r'; | |
522 #line - "cf.cpp" | |
523 } | |
524 | |
525 static int ag_rp_33(void) { | |
526 #line - "cf.syn" | |
527 return '\t'; | |
528 #line - "cf.cpp" | |
529 } | |
530 | |
531 static int ag_rp_34(void) { | |
532 #line - "cf.syn" | |
533 return '\v'; | |
534 #line - "cf.cpp" | |
535 } | |
536 | |
537 static int ag_rp_35(void) { | |
538 #line - "cf.syn" | |
539 return '\\'; | |
540 #line - "cf.cpp" | |
541 } | |
542 | |
543 static int ag_rp_36(void) { | |
544 #line - "cf.syn" | |
545 return '\?'; | |
546 #line - "cf.cpp" | |
547 } | |
548 | |
549 static int ag_rp_37(void) { | |
550 #line - "cf.syn" | |
551 return '\''; | |
552 #line - "cf.cpp" | |
553 } | |
554 | |
555 static int ag_rp_38(void) { | |
556 #line - "cf.syn" | |
557 return '"'; | |
558 #line - "cf.cpp" | |
559 } | |
560 | |
561 static int ag_rp_39(int n) { | |
562 #line - "cf.syn" | |
563 return n==0?cf_error("Null character in string"),0 : n; | |
564 #line - "cf.cpp" | |
565 } | |
566 | |
567 static int ag_rp_40(int n) { | |
568 #line - "cf.syn" | |
569 return n&7; | |
570 #line - "cf.cpp" | |
571 } | |
572 | |
573 static int ag_rp_41(int n, int d) { | |
574 #line - "cf.syn" | |
575 return n*8 + (d&7); | |
576 #line - "cf.cpp" | |
577 } | |
578 | |
579 static int ag_rp_42(int n, int d) { | |
580 #line - "cf.syn" | |
581 return n*8 + (d&7); | |
582 #line - "cf.cpp" | |
583 } | |
584 | |
585 static int ag_rp_43(int n) { | |
586 #line - "cf.syn" | |
587 return n==0?cf_error("Null character in string"),0 : n; | |
588 #line - "cf.cpp" | |
589 } | |
590 | |
591 static int ag_rp_44(int n) { | |
592 #line - "cf.syn" | |
593 return n; | |
594 #line - "cf.cpp" | |
595 } | |
596 | |
597 static void ag_rp_45(int c) { | |
598 #line - "cf.syn" | |
599 acs(c); | |
600 #line - "cf.cpp" | |
601 } | |
602 | |
603 static void ag_rp_46(int c) { | |
604 #line - "cf.syn" | |
605 acs(c); | |
606 #line - "cf.cpp" | |
607 } | |
608 | |
609 static void ag_rp_47(int c) { | |
610 #line - "cf.syn" | |
611 acs(c); | |
612 #line - "cf.cpp" | |
613 } | |
614 | |
615 static void ag_rp_48(int c) { | |
616 #line - "cf.syn" | |
617 acs(c); | |
618 #line - "cf.cpp" | |
619 } | |
620 | |
621 static void ag_rp_49(int c) { | |
622 #line - "cf.syn" | |
623 acs(c); | |
624 #line - "cf.cpp" | |
625 } | |
626 | |
627 static void ag_rp_50(int n) { | |
628 #line - "cf.syn" | |
629 acs(n); | |
630 #line - "cf.cpp" | |
631 } | |
632 | |
633 static void ag_rp_51(int n) { | |
634 #line - "cf.syn" | |
635 acs(n); | |
636 #line - "cf.cpp" | |
637 } | |
638 | |
639 static void ag_rp_52(int n) { | |
640 #line - "cf.syn" | |
641 acs(n); | |
642 #line - "cf.cpp" | |
643 } | |
644 | |
645 static void ag_rp_53(int n) { | |
646 #line - "cf.syn" | |
647 acs(n); | |
648 #line - "cf.cpp" | |
649 } | |
650 | |
651 static void ag_rp_54(void) { | |
652 #line - "cf.syn" | |
653 if (nest_comments) PCB.reduction_token = cf_c_comment_text_token; | |
654 #line - "cf.cpp" | |
655 } | |
656 | |
657 | |
658 #define READ_COUNTS | |
659 #define WRITE_COUNTS | |
660 #undef V | |
661 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
662 #undef VS | |
663 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
664 | |
665 #ifndef GET_CONTEXT | |
666 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
667 #endif | |
668 | |
669 typedef enum { | |
670 ag_action_1, | |
671 ag_action_2, | |
672 ag_action_3, | |
673 ag_action_4, | |
674 ag_action_5, | |
675 ag_action_6, | |
676 ag_action_7, | |
677 ag_action_8, | |
678 ag_action_9, | |
679 ag_action_10, | |
680 ag_action_11, | |
681 ag_action_12 | |
682 } ag_parser_action; | |
683 | |
684 | |
685 #ifndef NULL_VALUE_INITIALIZER | |
686 #define NULL_VALUE_INITIALIZER = 0 | |
687 #endif | |
688 | |
689 static int const ag_null_value NULL_VALUE_INITIALIZER; | |
690 | |
691 static const unsigned char ag_rpx[] = { | |
692 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
693 0, 0, 0, 1, 2, 3, 4, 5, 0, 6, 0, 0, 7, 8, 9, 0, 10, 11, | |
694 0, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
695 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 17, 18, 19, 20, 21, 22, | |
696 23, 0, 0, 0, 24, 0, 0, 25, 26, 0, 0, 0, 0, 27, 0, 0, 28, 29, | |
697 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 0, 0, 43, 44, 45, | |
698 46, 47, 48, 49, 50, 51, 52, 53, 0, 0, 0, 54 | |
699 }; | |
700 | |
701 static const unsigned char ag_key_itt[] = { | |
702 0 | |
703 }; | |
704 | |
705 static const unsigned short ag_key_pt[] = { | |
706 0 | |
707 }; | |
708 | |
709 static const unsigned char ag_key_ch[] = { | |
710 0, 42, 47,255, 47,255, 42, 47,255, 47,255, 42, 47,255, 88,120,255, 47, | |
711 48,255, 88,120,255, 48,255, 88,120,255, 47, 48,255, 34, 39, 63, 92, 97, | |
712 98,102,110,114,116,118,120,255, 92,255 | |
713 }; | |
714 | |
715 static const unsigned char ag_key_act[] = { | |
716 0,0,0,4,2,4,3,3,4,3,4,0,0,4,0,0,4,2,2,4,0,0,4,2,4,0,0,4,3,2,4,0,0,0,0, | |
717 0,0,0,0,0,0,0,0,4,2,4 | |
718 }; | |
719 | |
720 static const unsigned char ag_key_parm[] = { | |
721 0, 98, 49, 0, 0, 0, 97, 98, 0, 49, 0, 98, 49, 0, 61, 60, 0, 0, | |
722 0, 0, 61, 60, 0, 0, 0, 61, 60, 0, 98, 0, 0, 85, 84, 83, 82, 75, | |
723 76, 77, 78, 79, 80, 81, 93, 0, 0, 0 | |
724 }; | |
725 | |
726 static const unsigned char ag_key_jmp[] = { | |
727 0, 0, 0, 0, 1, 0, 0, 2, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, | |
728 14, 0, 0, 0, 0, 20, 0, 0, 0, 0, 6, 25, 0, 0, 0, 0, 0, 0, | |
729 0, 0, 0, 0, 0, 0, 0, 0, 31, 0 | |
730 }; | |
731 | |
732 static const unsigned char ag_key_index[] = { | |
733 4, 6, 4, 9, 0, 4, 4, 0, 0, 0, 9, 4, 0, 9, 0, 0, 0, 0, | |
734 17, 4, 0, 17, 23, 0, 0, 4, 28, 17, 17, 23, 44, 9, 0, 28, 4, 4, | |
735 4, 4, 0, 44, 44, 23, 44, 44, 44, 4, 4, 9, 0, 9, 44, 4, 0, 4 | |
736 }; | |
737 | |
738 static const unsigned char ag_key_ends[] = { | |
739 47,0, 42,0, 47,0, 42,0, | |
740 }; | |
741 | |
742 #define AG_TCV(x) ag_tcv[(x)] | |
743 | |
744 static const unsigned char ag_tcv[] = { | |
745 24,103,103,103,103,103,103,103,103, 39, 46, 48, 48, 44,103,103,103,103, | |
746 103,103,103,103,103,103,103,103, 24,103,103,103,103,103, 39,103, 68,103, | |
747 103,103,103,103, 13, 15, 35, 9,103, 7,103,103, 57,101,101,101,101,101, | |
748 101,101,102,102,103,103,103, 3,103,103,103, 62, 62, 62, 62, 62, 62,100, | |
749 100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100, | |
750 100,103, 88,103,103,100,103, 62, 62, 62, 62, 62, 62,100,100,100,100,100, | |
751 100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,103,103,103, | |
752 11,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
753 103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
754 103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
755 103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
756 103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
757 103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
758 103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103, | |
759 103,103,103,103 | |
760 }; | |
761 | |
762 #ifndef SYNTAX_ERROR | |
763 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
764 (PCB).error_message, (PCB).line, (PCB).column) | |
765 #endif | |
766 | |
767 #ifndef FIRST_LINE | |
768 #define FIRST_LINE 1 | |
769 #endif | |
770 | |
771 #ifndef FIRST_COLUMN | |
772 #define FIRST_COLUMN 1 | |
773 #endif | |
774 | |
775 #ifndef PARSER_STACK_OVERFLOW | |
776 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
777 "\nParser stack overflow, line %d, column %d\n",\ | |
778 (PCB).line, (PCB).column);} | |
779 #endif | |
780 | |
781 #ifndef REDUCTION_TOKEN_ERROR | |
782 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
783 "\nReduction token error, line %d, column %d\n", \ | |
784 (PCB).line, (PCB).column);} | |
785 #endif | |
786 | |
787 | |
788 #ifndef INPUT_CODE | |
789 #define INPUT_CODE(T) (T) | |
790 #endif | |
791 | |
792 typedef enum | |
793 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
794 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
795 | |
796 static void ag_get_key_word(int ag_k) { | |
797 int ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
798 const unsigned char *ag_p; | |
799 int ag_ch; | |
800 while (1) { | |
801 switch (ag_key_act[ag_k]) { | |
802 case ag_cf_end_key: { | |
803 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
804 do { | |
805 if ((ag_ch = *sp++) == 0) { | |
806 int ag_k1 = ag_key_parm[ag_k]; | |
807 int ag_k2 = ag_key_pt[ag_k1]; | |
808 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail; | |
809 (PCB).token_number = (cf_token_type) ag_key_pt[ag_k1 + 1]; | |
810 return; | |
811 } | |
812 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
813 goto ag_fail; | |
814 } | |
815 case ag_end_key: { | |
816 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
817 do { | |
818 if ((ag_ch = *sp++) == 0) { | |
819 (PCB).token_number = (cf_token_type) ag_key_parm[ag_k]; | |
820 return; | |
821 } | |
822 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
823 } | |
824 case ag_no_match_key: | |
825 ag_fail: | |
826 (PCB).la_ptr = (PCB).pointer + ag_save; | |
827 return; | |
828 case ag_cf_set_key: { | |
829 int ag_k1 = ag_key_parm[ag_k]; | |
830 int ag_k2 = ag_key_pt[ag_k1]; | |
831 ag_k = ag_key_jmp[ag_k]; | |
832 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) break; | |
833 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
834 (PCB).token_number = (cf_token_type) ag_key_pt[ag_k1+1]; | |
835 break; | |
836 } | |
837 case ag_set_key: | |
838 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
839 (PCB).token_number = (cf_token_type) ag_key_parm[ag_k]; | |
840 case ag_jmp_key: | |
841 ag_k = ag_key_jmp[ag_k]; | |
842 break; | |
843 case ag_accept_key: | |
844 (PCB).token_number = (cf_token_type) ag_key_parm[ag_k]; | |
845 return; | |
846 case ag_cf_accept_key: { | |
847 int ag_k1 = ag_key_parm[ag_k]; | |
848 int ag_k2 = ag_key_pt[ag_k1]; | |
849 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) | |
850 (PCB).la_ptr = (PCB).pointer + ag_save; | |
851 else (PCB).token_number = (cf_token_type) ag_key_pt[ag_k1+1]; | |
852 return; | |
853 } | |
854 } | |
855 ag_ch = CONVERT_CASE(*(PCB).la_ptr++); | |
856 ag_p = &ag_key_ch[ag_k]; | |
857 if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++; | |
858 if (ag_ch > 255 || *ag_p != ag_ch) { | |
859 (PCB).la_ptr = (PCB).pointer + ag_save; | |
860 return; | |
861 } | |
862 ag_k = (int) (ag_p - ag_key_ch); | |
863 } | |
864 } | |
865 | |
866 | |
867 #ifndef AG_NEWLINE | |
868 #define AG_NEWLINE 10 | |
869 #endif | |
870 | |
871 #ifndef AG_RETURN | |
872 #define AG_RETURN 13 | |
873 #endif | |
874 | |
875 #ifndef AG_FORMFEED | |
876 #define AG_FORMFEED 12 | |
877 #endif | |
878 | |
879 #ifndef AG_TABCHAR | |
880 #define AG_TABCHAR 9 | |
881 #endif | |
882 | |
883 static void ag_track(void) { | |
884 int ag_k = (int) ((PCB).la_ptr - (PCB).pointer); | |
885 while (ag_k--) { | |
886 switch (*(PCB).pointer++) { | |
887 case AG_NEWLINE: | |
888 (PCB).column = 1, (PCB).line++; | |
889 case AG_RETURN: | |
890 case AG_FORMFEED: | |
891 break; | |
892 case AG_TABCHAR: | |
893 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
894 break; | |
895 default: | |
896 (PCB).column++; | |
897 } | |
898 } | |
899 } | |
900 | |
901 | |
902 static void ag_prot(void) { | |
903 int ag_k; | |
904 ag_k = 128 - ++(PCB).btsx; | |
905 if (ag_k <= (PCB).ssx) { | |
906 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
907 PARSER_STACK_OVERFLOW; | |
908 return; | |
909 } | |
910 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
911 (PCB).bts[ag_k] = (PCB).ssx; | |
912 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
913 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
914 (PCB).cs[ag_k] = (PCB).cs[(PCB).ssx]; | |
915 } | |
916 | |
917 static void ag_undo(void) { | |
918 if ((PCB).drt == -1) return; | |
919 while ((PCB).btsx) { | |
920 int ag_k = 128 - (PCB).btsx; | |
921 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
922 (PCB).ssx = (PCB).bts[ag_k]; | |
923 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
924 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
925 (PCB).cs[(PCB).ssx] = (PCB).cs[ag_k]; | |
926 } | |
927 (PCB).token_number = (cf_token_type) (PCB).drt; | |
928 (PCB).ssx = (PCB).dssx; | |
929 (PCB).sn = (PCB).dsn; | |
930 (PCB).drt = -1; | |
931 } | |
932 | |
933 | |
934 | |
935 static const int ag_rtt[] = { | |
936 40, 96, 0 | |
937 }; | |
938 | |
939 static const unsigned char ag_tstt[] = { | |
940 100,98,62,49,46,44,39,24,11,0,1,16,17,18,40,96, | |
941 103,102,101,100,98,97,88,68,62,57,48,46,44,39,35,15,13,11,9,7,3,0,40,96, | |
942 98,39,0,16,40,96, | |
943 100,62,49,46,44,24,11,0,10,19,20,21,22,23,25,36,42,45, | |
944 103,102,101,100,88,68,62,57,48,46,44,39,35,15,13,11,9,7,3,0,51,52, | |
945 100,98,62,49,46,44,39,0,4,5,16,17,40,41,42,43,45,96, | |
946 102,101,100,98,62,57,49,46,44,39,35,24,15,13,3,0,16,17,18,40,96, | |
947 46,0, | |
948 46,44,0,45, | |
949 100,62,0,25,36, | |
950 3,0,2, | |
951 100,98,62,49,48,46,44,39,24,11,0,16,40,42,45,47,96, | |
952 100,62,11,0,10,19,25,36, | |
953 49,46,44,24,0,20,42,45, | |
954 24,0, | |
955 103,102,101,100,88,68,62,57,48,39,35,15,13,11,9,7,3,0, | |
956 46,0, | |
957 46,44,0,43,45, | |
958 102,101,100,98,68,62,61,60,57,49,46,44,39,35,13,9,7,0,16,40,41,42,43,45,96, | |
959 102,101,100,98,62,57,39,0,16,40,96, | |
960 46,0, | |
961 102,101,100,98,68,62,61,60,57,49,46,44,39,9,7,0,4,5,16,17,40,41,42,43,45,96, | |
962 102,101,100,68,62,61,60,57,9,7,0,6,8,25,26,27,28,36,64,65,66, | |
963 46,44,0,45, | |
964 46,0, | |
965 100,98,62,49,48,46,44,39,24,11,0,16,40,42,45,47,96, | |
966 98,39,0,16,17,40,96, | |
967 102,101,98,61,60,57,49,46,44,39,0,4,5,16,17,40,41,42,43,45,96, | |
968 102,101,98,61,60,57,49,46,44,39,0,4,5,16,17,40,41,42,43,45,96, | |
969 102,101,61,60,57,0,53,56,59,63, | |
970 103,102,101,100,93,88,85,84,83,82,81,80,79,78,77,76,75,62,57,48,39,35,15,13, | |
971 11,9,7,3,0,67,69,70,71,72,74,86,87,89,90,91,92, | |
972 35,13,0,12,29,30,31,32,33,34, | |
973 46,0, | |
974 98,39,0,16,40,96, | |
975 102,101,62,57,0, | |
976 101,57,0, | |
977 102,101,57,0, | |
978 98,49,46,44,39,24,0,16,17,18,40,96, | |
979 101,57,0, | |
980 101,57,0, | |
981 101,57,0, | |
982 61,60,0,59, | |
983 102,62,0, | |
984 102,101,62,57,0, | |
985 103,100,93,88,85,84,83,82,81,80,79,78,77,76,75,68,48,39,35,15,13,11,9,7,3,0, | |
986 72,74,86,87,89,90,91,92, | |
987 98,49,46,44,39,35,13,0,4,5,16,17,40,41,42,43,45,96, | |
988 100,98,62,49,46,44,39,35,24,15,13,0,16,17,18,40,96, | |
989 100,62,0,25,36, | |
990 35,13,0,12,29,30,31,32,33,34, | |
991 35,13,0,12,31,32,33,34, | |
992 102,101,62,57,0, | |
993 98,49,46,44,39,24,0,16,17,18,40,96, | |
994 15,0,14, | |
995 98,49,46,44,39,24,15,0,16,17,18,40,96, | |
996 | |
997 }; | |
998 | |
999 | |
1000 static unsigned const char ag_astt[595] = { | |
1001 8,1,8,8,8,8,1,5,8,7,0,1,1,1,1,1,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, | |
1002 7,2,1,1,9,5,3,3,1,2,2,1,8,1,8,1,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5, | |
1003 5,1,1,1,1,1,1,1,1,7,1,3,5,1,5,1,8,1,1,7,3,3,1,1,1,3,1,3,1,1,10,10,10,1,10, | |
1004 10,5,5,5,1,5,5,5,5,5,7,1,1,3,1,1,3,7,8,1,7,1,2,2,7,2,1,1,4,1,5,1,5,1,9,8,1, | |
1005 9,5,5,7,3,3,1,1,3,1,2,2,1,5,1,3,1,1,1,8,1,5,7,1,1,1,3,7,9,9,9,9,9,9,9,9,9, | |
1006 9,9,9,9,9,9,9,9,5,1,7,8,1,7,3,1,5,5,5,1,5,5,5,5,5,1,8,1,9,5,5,5,5,7,3,3,3, | |
1007 1,3,1,1,2,2,2,1,2,2,9,5,3,3,1,3,7,5,5,5,1,5,5,5,5,5,1,8,1,1,5,5,7,3,3,1,1, | |
1008 1,3,1,3,1,1,5,5,2,2,2,5,5,5,1,1,7,2,2,1,2,2,2,1,1,2,1,8,1,7,1,3,7,5,1,5,1, | |
1009 9,8,1,9,5,5,7,3,3,1,1,3,1,1,1,5,1,1,1,1,5,5,1,5,5,5,1,8,1,1,7,3,3,1,1,1,3, | |
1010 1,3,1,1,5,5,1,5,5,5,1,8,1,1,7,3,3,1,1,1,3,1,3,1,1,2,2,2,2,2,7,1,1,1,1,2,2, | |
1011 2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,7,1,1,1,1,2,2,2,1,1,2, | |
1012 2,2,1,1,5,2,2,1,2,1,1,1,3,7,1,9,5,3,3,1,10,10,10,10,5,10,10,5,10,10,10,5,1, | |
1013 5,5,5,1,5,7,1,1,2,1,1,2,2,7,2,2,5,2,2,5,2,2,7,1,2,2,5,10,10,10,10,5,2,2,1, | |
1014 1,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,7,2,2,2,1,1,2,2,2,1,1,8,1,1,5, | |
1015 5,7,3,3,1,1,1,3,1,3,1,1,5,1,5,5,5,5,1,5,5,5,5,7,1,1,2,1,1,2,2,5,2,1,1,1,7, | |
1016 2,1,1,1,1,1,1,1,1,5,2,2,1,2,1,10,10,10,10,4,1,5,5,5,1,5,7,1,1,3,1,1,1,7,2, | |
1017 1,5,5,5,1,5,5,7,1,1,3,1,1 | |
1018 }; | |
1019 | |
1020 | |
1021 static const unsigned char ag_pstt[] = { | |
1022 3,1,3,3,3,3,2,10,3,0,0,2,2,3,2,1, | |
1023 118,118,118,118,1,116,118,118,118,118,118,118,118,118,118,118,118,118,118, | |
1024 118,118,1,119,1, | |
1025 1,9,11,9,9,1, | |
1026 38,38,4,7,7,14,5,3,9,13,11,13,12,14,10,6,8,7, | |
1027 15,15,15,15,15,15,15,15,15,62,62,15,15,15,15,15,15,15,15,4,15,64, | |
1028 1,1,1,4,16,16,18,5,6,6,18,18,18,6,17,6,16,1, | |
1029 39,39,39,1,39,39,10,10,10,19,10,10,10,10,10,6,19,19,41,19,1, | |
1030 57,7, | |
1031 20,20,8,20, | |
1032 38,38,9,22,6, | |
1033 21,21,22, | |
1034 16,1,16,4,59,24,24,58,16,16,11,58,58,23,24,58,1, | |
1035 38,38,5,19,9,14,10,6, | |
1036 4,7,7,18,13,25,8,7, | |
1037 20,14, | |
1038 61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,63, | |
1039 26,16, | |
1040 16,16,17,47,16, | |
1041 44,44,44,1,44,44,44,44,44,4,16,16,9,44,44,44,44,18,9,9,45,17,45,16,1, | |
1042 40,40,40,1,40,40,9,11,9,9,1, | |
1043 56,20, | |
1044 1,1,1,1,1,1,1,1,1,4,16,16,18,1,1,21,3,3,18,18,18,3,17,3,16,1, | |
1045 77,77,38,85,38,77,77,77,27,28,22,80,79,31,23,24,25,6,29,79,30, | |
1046 32,32,23,32, | |
1047 54,24, | |
1048 15,1,15,4,59,24,24,58,15,15,25,58,58,23,24,58,1, | |
1049 1,33,51,33,33,33,1, | |
1050 1,1,1,1,1,1,4,16,16,18,27,5,5,18,18,18,5,17,5,16,1, | |
1051 1,1,1,1,1,1,4,16,16,18,28,4,4,18,18,18,4,17,4,16,1, | |
1052 65,65,70,69,67,29,36,35,34,37, | |
1053 107,108,108,107,41,38,98,97,96,95,94,93,92,91,90,89,88,108,108,107,107,107, | |
1054 107,107,107,107,107,107,30,44,43,42,44,107,107,99,40,39,112,105,114, | |
1055 46,45,26,31,27,49,27,48,49,47, | |
1056 55,32, | |
1057 1,9,52,9,9,1, | |
1058 71,71,72,71,75, | |
1059 68,68,74, | |
1060 66,66,66,73, | |
1061 1,10,10,10,2,10,37,2,2,76,2,1, | |
1062 100,100,38, | |
1063 102,102,104, | |
1064 101,101,103, | |
1065 70,69,41,50, | |
1066 111,111,83, | |
1067 110,110,110,110,82, | |
1068 109,109,41,38,98,97,96,95,94,93,92,91,90,89,88,51,109,109,109,109,109,109, | |
1069 109,109,109,44,109,109,99,40,39,113,105,115, | |
1070 1,4,16,16,18,1,1,45,7,7,18,18,18,7,17,7,16,1, | |
1071 10,1,10,10,10,10,2,10,10,10,10,46,2,2,35,2,1, | |
1072 38,38,33,34,6, | |
1073 46,45,48,31,52,49,52,48,49,47, | |
1074 46,45,28,31,30,48,37,47, | |
1075 71,71,72,71,106, | |
1076 1,10,10,10,2,10,51,2,2,81,2,1, | |
1077 53,52,32, | |
1078 1,10,10,10,2,10,10,53,2,2,12,2,1, | |
1079 | |
1080 }; | |
1081 | |
1082 | |
1083 static const unsigned short ag_sbt[] = { | |
1084 0, 16, 40, 46, 64, 86, 104, 125, 127, 131, 136, 139, 156, 164, | |
1085 172, 174, 192, 194, 199, 224, 235, 237, 263, 284, 288, 290, 307, 314, | |
1086 335, 356, 366, 407, 417, 419, 425, 430, 433, 437, 449, 452, 455, 458, | |
1087 462, 465, 470, 504, 522, 539, 544, 554, 562, 567, 579, 582, 595 | |
1088 }; | |
1089 | |
1090 | |
1091 static const unsigned short ag_sbe[] = { | |
1092 9, 37, 42, 53, 83, 93, 119, 126, 129, 133, 137, 149, 159, 168, | |
1093 173, 191, 193, 196, 216, 231, 236, 252, 273, 286, 289, 300, 309, 324, | |
1094 345, 361, 394, 409, 418, 421, 429, 432, 436, 443, 451, 454, 457, 460, | |
1095 464, 469, 495, 511, 533, 541, 546, 556, 566, 573, 580, 589, 595 | |
1096 }; | |
1097 | |
1098 | |
1099 static const unsigned char ag_fl[] = { | |
1100 1,0,1,2,2,2,2,2,1,2,0,1,2,1,2,2,1,0,1,1,3,1,2,3,3,3,1,2,1,1,2,1,3,1,2, | |
1101 2,1,2,1,2,3,2,1,1,1,2,1,2,1,0,1,2,3,1,2,3,3,2,2,2,1,2,0,1,2,1,2,1,2,1, | |
1102 1,2,2,1,1,1,3,0,1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1, | |
1103 1,2,1,1,2,2,2,1,2,1,2,2,1,2,2 | |
1104 }; | |
1105 | |
1106 static const unsigned char ag_ptt[] = { | |
1107 0, 5, 5, 2, 6, 8, 10, 12, 17, 17, 18, 18, 14, 21, 21, 22, 22, 23, | |
1108 23, 23, 1, 19, 19, 19, 19, 19, 26, 26, 29, 29, 29, 32, 31, 33, 33, 34, | |
1109 30, 30, 36, 36, 36, 25, 16, 16, 4, 4, 4, 41, 41, 45, 45, 43, 43, 47, | |
1110 47, 47, 20, 20, 20, 20, 51, 51, 52, 52, 42, 53, 53, 56, 56, 59, 59, 59, | |
1111 59, 63, 63, 63, 28, 65, 65, 64, 64, 27, 67, 67, 67, 66, 72, 72, 74, 74, | |
1112 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 87, 89, 86, 91, 91, 90, 92, 69, | |
1113 69, 69, 69, 69, 70, 70, 71, 71, 40, 96, 96, 40 | |
1114 }; | |
1115 | |
1116 static const unsigned char *ag_valid(int ag_k) { | |
1117 const unsigned char *ag_tp = &ag_tstt[ag_sbt[(PCB).sn+1]]; | |
1118 while (*--ag_tp != (unsigned char) ag_k) if (*ag_tp == 0) return NULL; | |
1119 return ag_tp; | |
1120 } | |
1121 | |
1122 int cf_change_reduction(cf_token_type ag_k) { | |
1123 if (!ag_valid(ag_k)) return 0; | |
1124 (PCB).reduction_token = ag_k; | |
1125 return 1; | |
1126 } | |
1127 | |
1128 static void ag_default(const int *ag_tp) { | |
1129 (PCB).ag_dsn = (PCB).sn; | |
1130 (PCB).ag_dtl = ag_tp; | |
1131 while (!ag_valid((cf_token_type) *ag_tp)) ag_tp++; | |
1132 (PCB).reduction_token = (cf_token_type) *ag_tp; | |
1133 } | |
1134 | |
1135 | |
1136 | |
1137 static void ag_ra(void) | |
1138 { | |
1139 switch(ag_rpx[(PCB).ag_ap]) { | |
1140 case 1: ag_rp_1(); break; | |
1141 case 2: ag_rp_2(); break; | |
1142 case 3: ag_rp_3(); break; | |
1143 case 4: ag_rp_4(); break; | |
1144 case 5: ag_rp_5(VS(2)); break; | |
1145 case 6: ag_rp_6(); break; | |
1146 case 7: ag_rp_7(); break; | |
1147 case 8: VS(0) = ag_rp_8(); break; | |
1148 case 9: ag_rp_9(); break; | |
1149 case 10: ag_rp_10(); break; | |
1150 case 11: ag_rp_11(); break; | |
1151 case 12: ag_rp_12(); break; | |
1152 case 13: ag_rp_13(VS(0)); break; | |
1153 case 14: ag_rp_14(VS(1)); break; | |
1154 case 15: ag_rp_15(VS(2)); break; | |
1155 case 16: VS(0) = ag_rp_16(VS(0)); break; | |
1156 case 17: VS(0) = ag_rp_17(VS(0), VS(1)); break; | |
1157 case 18: VS(0) = ag_rp_18(); break; | |
1158 case 19: VS(0) = ag_rp_19(VS(0), VS(1)); break; | |
1159 case 20: VS(0) = ag_rp_20(); break; | |
1160 case 21: VS(0) = ag_rp_21(); break; | |
1161 case 22: VS(0) = ag_rp_22(VS(0), VS(1)); break; | |
1162 case 23: VS(0) = ag_rp_23(VS(0), VS(1)); break; | |
1163 case 24: VS(0) = ag_rp_24(VS(0), VS(1)); break; | |
1164 case 25: VS(0) = ag_rp_25(); break; | |
1165 case 26: VS(0) = ag_rp_26(); break; | |
1166 case 27: ag_rp_27(); break; | |
1167 case 28: VS(0) = ag_rp_28(); break; | |
1168 case 29: VS(0) = ag_rp_29(); break; | |
1169 case 30: VS(0) = ag_rp_30(); break; | |
1170 case 31: VS(0) = ag_rp_31(); break; | |
1171 case 32: VS(0) = ag_rp_32(); break; | |
1172 case 33: VS(0) = ag_rp_33(); break; | |
1173 case 34: VS(0) = ag_rp_34(); break; | |
1174 case 35: VS(0) = ag_rp_35(); break; | |
1175 case 36: VS(0) = ag_rp_36(); break; | |
1176 case 37: VS(0) = ag_rp_37(); break; | |
1177 case 38: VS(0) = ag_rp_38(); break; | |
1178 case 39: VS(0) = ag_rp_39(VS(0)); break; | |
1179 case 40: VS(0) = ag_rp_40(VS(1)); break; | |
1180 case 41: VS(0) = ag_rp_41(VS(0), VS(1)); break; | |
1181 case 42: VS(0) = ag_rp_42(VS(0), VS(1)); break; | |
1182 case 43: VS(0) = ag_rp_43(VS(0)); break; | |
1183 case 44: VS(0) = ag_rp_44(VS(1)); break; | |
1184 case 45: ag_rp_45(VS(0)); break; | |
1185 case 46: ag_rp_46(VS(0)); break; | |
1186 case 47: ag_rp_47(VS(1)); break; | |
1187 case 48: ag_rp_48(VS(1)); break; | |
1188 case 49: ag_rp_49(VS(1)); break; | |
1189 case 50: ag_rp_50(VS(0)); break; | |
1190 case 51: ag_rp_51(VS(1)); break; | |
1191 case 52: ag_rp_52(VS(0)); break; | |
1192 case 53: ag_rp_53(VS(1)); break; | |
1193 case 54: ag_default(&ag_rtt[0]); ag_rp_54(); break; | |
1194 } | |
1195 (PCB).la_ptr = (PCB).pointer; | |
1196 } | |
1197 | |
1198 | |
1199 static const unsigned char ag_ctn[] = { | |
1200 0,0, 40,1, 0,0, 0,0, 42,1, 10,1, 25,1, 20,1, 20,1, 19,1, 19,1, 20,1, | |
1201 22,1, 22,1, 0,0, 0,0, 0,0, 41,1, 0,0, 0,0, 20,2, 2,1, 19,2, 47,1, | |
1202 47,1, 20,1, 0,0, 8,1, 6,1, 28,1, 27,1, 26,1, 47,2, 0,0, 59,1, 56,1, | |
1203 53,1, 28,2, 72,1, 72,1, 72,1, 0,0, 67,1, 67,1, 67,1, 31,1, 34,1, 0,0, | |
1204 31,1, 29,1, 59,1, 27,3, 31,2, 0,0 | |
1205 }; | |
1206 | |
1207 #ifndef MISSING_FORMAT | |
1208 #define MISSING_FORMAT "Missing %s" | |
1209 #endif | |
1210 #ifndef UNEXPECTED_FORMAT | |
1211 #define UNEXPECTED_FORMAT "Unexpected %s" | |
1212 #endif | |
1213 #ifndef UNNAMED_TOKEN | |
1214 #define UNNAMED_TOKEN "input" | |
1215 #endif | |
1216 | |
1217 | |
1218 static void ag_diagnose(void) { | |
1219 int ag_snd = (PCB).sn; | |
1220 int ag_k = ag_sbt[ag_snd]; | |
1221 | |
1222 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
1223 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
1224 } | |
1225 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
1226 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
1227 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
1228 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
1229 } | |
1230 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
1231 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
1232 } | |
1233 else if (isprint(INPUT_CODE((*(PCB).pointer))) && INPUT_CODE((*(PCB).pointer)) != '\\') { | |
1234 char buf[20]; | |
1235 sprintf(buf, "\'%c\'", (char) INPUT_CODE((*(PCB).pointer))); | |
1236 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
1237 } | |
1238 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
1239 (PCB).error_message = (PCB).ag_msg; | |
1240 | |
1241 | |
1242 { | |
1243 int ag_sx, ag_t; | |
1244 | |
1245 ag_sx = (PCB).ssx; | |
1246 (PCB).ss[ag_sx] = (PCB).sn; | |
1247 do { | |
1248 while (ag_sx && ag_ctn[2*(ag_snd = (PCB).ss[ag_sx])] == 0) ag_sx--; | |
1249 if (ag_sx) { | |
1250 ag_t = ag_ctn[2*ag_snd]; | |
1251 ag_sx -= ag_ctn[2*ag_snd +1]; | |
1252 ag_snd = (PCB).ss[ag_sx]; | |
1253 } | |
1254 else { | |
1255 ag_snd = 0; | |
1256 ag_t = ag_ptt[0]; | |
1257 } | |
1258 } while (ag_sx && *TOKEN_NAMES[ag_t]==0); | |
1259 if (*TOKEN_NAMES[ag_t] == 0) ag_t = 0; | |
1260 (PCB).error_frame_ssx = ag_sx; | |
1261 (PCB).error_frame_token = (cf_token_type) ag_t; | |
1262 } | |
1263 | |
1264 | |
1265 } | |
1266 static int ag_action_1_r_proc(void); | |
1267 static int ag_action_2_r_proc(void); | |
1268 static int ag_action_3_r_proc(void); | |
1269 static int ag_action_4_r_proc(void); | |
1270 static int ag_action_1_s_proc(void); | |
1271 static int ag_action_3_s_proc(void); | |
1272 static int ag_action_1_proc(void); | |
1273 static int ag_action_2_proc(void); | |
1274 static int ag_action_3_proc(void); | |
1275 static int ag_action_4_proc(void); | |
1276 static int ag_action_5_proc(void); | |
1277 static int ag_action_6_proc(void); | |
1278 static int ag_action_7_proc(void); | |
1279 static int ag_action_8_proc(void); | |
1280 static int ag_action_9_proc(void); | |
1281 static int ag_action_10_proc(void); | |
1282 static int ag_action_11_proc(void); | |
1283 static int ag_action_8_proc(void); | |
1284 | |
1285 | |
1286 static int (*const ag_r_procs_scan[])(void) = { | |
1287 ag_action_1_r_proc, | |
1288 ag_action_2_r_proc, | |
1289 ag_action_3_r_proc, | |
1290 ag_action_4_r_proc | |
1291 }; | |
1292 | |
1293 static int (*const ag_s_procs_scan[])(void) = { | |
1294 ag_action_1_s_proc, | |
1295 ag_action_2_r_proc, | |
1296 ag_action_3_s_proc, | |
1297 ag_action_4_r_proc | |
1298 }; | |
1299 | |
1300 static int (*const ag_gt_procs_scan[])(void) = { | |
1301 ag_action_1_proc, | |
1302 ag_action_2_proc, | |
1303 ag_action_3_proc, | |
1304 ag_action_4_proc, | |
1305 ag_action_5_proc, | |
1306 ag_action_6_proc, | |
1307 ag_action_7_proc, | |
1308 ag_action_8_proc, | |
1309 ag_action_9_proc, | |
1310 ag_action_10_proc, | |
1311 ag_action_11_proc, | |
1312 ag_action_8_proc | |
1313 }; | |
1314 | |
1315 | |
1316 static int ag_rns(int ag_t, int *ag_sx, int ag_snd) { | |
1317 while (1) { | |
1318 int ag_act, ag_k = ag_sbt[ag_snd], ag_lim = ag_sbt[ag_snd+1]; | |
1319 int ag_p; | |
1320 | |
1321 while (ag_k < ag_lim && ag_tstt[ag_k] != ag_t) ag_k++; | |
1322 if (ag_k == ag_lim) break; | |
1323 ag_act = ag_astt[ag_k]; | |
1324 ag_p = ag_pstt[ag_k]; | |
1325 if (ag_act == ag_action_2) return ag_p; | |
1326 if (ag_act == ag_action_10 || ag_act == ag_action_11) { | |
1327 (*ag_sx)--; | |
1328 return ag_snd; | |
1329 } | |
1330 if (ag_act != ag_action_3 && | |
1331 ag_act != ag_action_4) break; | |
1332 *ag_sx -= (ag_fl[ag_p] - 1); | |
1333 ag_snd = (PCB).ss[*ag_sx]; | |
1334 ag_t = ag_ptt[ag_p]; | |
1335 } | |
1336 return 0; | |
1337 } | |
1338 | |
1339 static int ag_jns(int ag_t) { | |
1340 int ag_k; | |
1341 | |
1342 ag_k = ag_sbt[(PCB).sn]; | |
1343 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1344 while (1) { | |
1345 int ag_p = ag_pstt[ag_k]; | |
1346 int ag_sd; | |
1347 | |
1348 switch (ag_astt[ag_k]) { | |
1349 case ag_action_2: | |
1350 GET_CONTEXT; | |
1351 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1352 return ag_p; | |
1353 case ag_action_10: | |
1354 case ag_action_11: | |
1355 return (PCB).ss[(PCB).ssx--]; | |
1356 case ag_action_9: | |
1357 GET_CONTEXT; | |
1358 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1359 (PCB).ssx++; | |
1360 (PCB).sn = ag_p; | |
1361 ag_k = ag_sbt[(PCB).sn]; | |
1362 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1363 continue; | |
1364 case ag_action_3: | |
1365 case ag_action_4: | |
1366 ag_sd = ag_fl[ag_p] - 1; | |
1367 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1368 else GET_CONTEXT; | |
1369 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1370 ag_t = ag_ptt[ag_p]; | |
1371 ag_k = ag_sbt[(PCB).sn+1]; | |
1372 while (ag_tstt[--ag_k] != ag_t); | |
1373 continue; | |
1374 case ag_action_5: | |
1375 case ag_action_6: | |
1376 if (ag_fl[ag_p]) break; | |
1377 (PCB).sn = ag_rns(ag_ptt[ag_p],&(PCB).ssx, (PCB).sn); | |
1378 (PCB).ss[++(PCB).ssx] = (PCB).sn; | |
1379 ag_k = ag_sbt[(PCB).sn]; | |
1380 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1381 continue; | |
1382 } | |
1383 break; | |
1384 } | |
1385 return 0; | |
1386 } | |
1387 | |
1388 | |
1389 static int ag_atx(int ag_t, int *ag_sx, int ag_snd) { | |
1390 int ag_k, ag_f; | |
1391 int ag_save_btsx = (PCB).btsx; | |
1392 int ag_flag = 1; | |
1393 | |
1394 while (1) { | |
1395 int ag_a; | |
1396 | |
1397 (PCB).bts[128 - ++(PCB).btsx] = *ag_sx; | |
1398 (PCB).ss[128 - (PCB).btsx] = (PCB).ss[*ag_sx]; | |
1399 (PCB).ss[*ag_sx] = ag_snd; | |
1400 ag_k = ag_sbt[ag_snd]; | |
1401 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1402 ag_a = ag_astt[ag_k]; | |
1403 if (ag_a == ag_action_2 || | |
1404 ag_a == ag_action_3 || | |
1405 ag_a == ag_action_10 || | |
1406 ag_a == ag_action_11 || | |
1407 ag_a == ag_action_1 || | |
1408 ag_a == ag_action_4) break; | |
1409 if ((ag_a == ag_action_5 || | |
1410 ag_a == ag_action_6) && | |
1411 (ag_k = ag_fl[ag_f = ag_pstt[ag_k]]) == 0) { | |
1412 ag_snd = ag_rns(ag_ptt[ag_f],ag_sx, (PCB).ss[*ag_sx]); | |
1413 (*ag_sx)++; | |
1414 continue; | |
1415 } | |
1416 if (ag_a == ag_action_9) { | |
1417 ag_snd = ag_pstt[ag_k]; | |
1418 (*ag_sx)++; | |
1419 continue; | |
1420 } | |
1421 ag_flag = 0; | |
1422 break; | |
1423 } | |
1424 while ((PCB).btsx > ag_save_btsx) { | |
1425 *ag_sx = (PCB).bts[128 - (PCB).btsx]; | |
1426 (PCB).ss[*ag_sx] = (PCB).ss[128 - (PCB).btsx--]; | |
1427 } | |
1428 return ag_flag; | |
1429 } | |
1430 | |
1431 | |
1432 static int ag_tst_tkn(void) { | |
1433 int ag_rk, ag_sx, ag_snd = (PCB).sn; | |
1434 | |
1435 (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1436 (PCB).la_ptr++; | |
1437 if (ag_key_index[(PCB).sn]) { | |
1438 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1439 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1440 if (ag_ch <= 255) { | |
1441 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1442 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1443 } | |
1444 } | |
1445 for (ag_rk = 0; ag_rk < (PCB).ag_lrss; ag_rk += 2) { | |
1446 ag_sx = (PCB).ag_rss[ag_rk]; | |
1447 if (ag_sx > (PCB).ssx || ag_sx > (PCB).ag_min_depth) continue; | |
1448 (PCB).sn = (PCB).ag_rss[ag_rk + 1]; | |
1449 if (ag_atx((PCB).token_number, &ag_sx, (PCB).sn)) break; | |
1450 } | |
1451 (PCB).sn = ag_snd; | |
1452 return ag_rk; | |
1453 } | |
1454 | |
1455 static void ag_set_error_procs(void); | |
1456 | |
1457 static void ag_auto_resynch(void) { | |
1458 int ag_sx, ag_rk; | |
1459 int ag_rk1, ag_rk2, ag_tk1; | |
1460 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1461 if ((PCB).ag_error_depth && (PCB).ag_min_depth >= (PCB).ag_error_depth) { | |
1462 (PCB).ssx = (PCB).ag_error_depth; | |
1463 (PCB).sn = (PCB).ss[(PCB).ssx]; | |
1464 } | |
1465 else { | |
1466 ag_diagnose(); | |
1467 SYNTAX_ERROR; | |
1468 if ((PCB).exit_flag != AG_RUNNING_CODE) return; | |
1469 (PCB).ag_error_depth = (PCB).ag_min_depth = 0; | |
1470 (PCB).ag_lrss = 0; | |
1471 (PCB).ss[ag_sx = (PCB).ssx] = (PCB).sn; | |
1472 (PCB).ag_min_depth = (PCB).ag_rss[(PCB).ag_lrss++] = ag_sx; | |
1473 (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn; | |
1474 while (ag_sx && (PCB).ag_lrss < 2*128) { | |
1475 int ag_t = 0, ag_x, ag_s, ag_sxs = ag_sx; | |
1476 | |
1477 while (ag_sx && (ag_t = ag_ctn[2*(PCB).sn]) == 0) (PCB).sn = (PCB).ss[--ag_sx]; | |
1478 if (ag_t) (PCB).sn = (PCB).ss[ag_sx -= ag_ctn[2*(PCB).sn +1]]; | |
1479 else { | |
1480 if (ag_sx == 0) (PCB).sn = 0; | |
1481 ag_t = ag_ptt[0]; | |
1482 } | |
1483 if ((ag_s = ag_rns(ag_t, &ag_sx, (PCB).sn)) == 0) break; | |
1484 for (ag_x = 0; ag_x < (PCB).ag_lrss; ag_x += 2) | |
1485 if ((PCB).ag_rss[ag_x] == ag_sx + 1 && (PCB).ag_rss[ag_x+1] == ag_s) break; | |
1486 if (ag_x == (PCB).ag_lrss) { | |
1487 (PCB).ag_rss[(PCB).ag_lrss++] = ++ag_sx; | |
1488 (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn = ag_s; | |
1489 } | |
1490 else if (ag_sx >= ag_sxs) ag_sx--; | |
1491 } | |
1492 ag_set_error_procs(); | |
1493 } | |
1494 (PCB).la_ptr = (PCB).pointer; | |
1495 if ((PCB).ssx > (PCB).ag_min_depth) (PCB).ag_min_depth = (PCB).ssx; | |
1496 while (1) { | |
1497 ag_rk1 = ag_tst_tkn(); | |
1498 if ((PCB).token_number == 24) | |
1499 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;} | |
1500 if (ag_rk1 < (PCB).ag_lrss) break; | |
1501 {(PCB).la_ptr = (PCB).pointer + 1; ag_track();} | |
1502 } | |
1503 ag_tk1 = (PCB).token_number; | |
1504 ag_track(); | |
1505 ag_rk2 = ag_tst_tkn(); | |
1506 if (ag_rk2 < ag_rk1) {ag_rk = ag_rk2; ag_track();} | |
1507 else {ag_rk = ag_rk1; (PCB).token_number = (cf_token_type) ag_tk1; (PCB).la_ptr = (PCB).pointer;} | |
1508 (PCB).ag_min_depth = (PCB).ssx = (PCB).ag_rss[ag_rk++]; | |
1509 (PCB).sn = (PCB).ss[(PCB).ssx] = (PCB).ag_rss[ag_rk]; | |
1510 (PCB).sn = ag_jns((PCB).token_number); | |
1511 if ((PCB).ag_error_depth == 0 || (PCB).ag_error_depth > (PCB).ssx) | |
1512 (PCB).ag_error_depth = (PCB).ssx; | |
1513 if (++(PCB).ssx >= 128) { | |
1514 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
1515 PARSER_STACK_OVERFLOW; | |
1516 return; | |
1517 } | |
1518 GET_CONTEXT; | |
1519 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1520 (PCB).ag_tmp_depth = (PCB).ag_min_depth; | |
1521 (PCB).la_ptr = (PCB).pointer; | |
1522 return; | |
1523 } | |
1524 | |
1525 | |
1526 static int ag_action_10_proc(void) { | |
1527 int ag_t = (PCB).token_number; | |
1528 (PCB).btsx = 0, (PCB).drt = -1; | |
1529 do { | |
1530 ag_track(); | |
1531 (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1532 (PCB).la_ptr++; | |
1533 if (ag_key_index[(PCB).sn]) { | |
1534 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1535 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1536 if (ag_ch <= 255) { | |
1537 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1538 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1539 } | |
1540 } | |
1541 } while ((PCB).token_number == (cf_token_type) ag_t); | |
1542 (PCB).la_ptr = (PCB).pointer; | |
1543 return 1; | |
1544 } | |
1545 | |
1546 static int ag_action_11_proc(void) { | |
1547 int ag_t = (PCB).token_number; | |
1548 | |
1549 (PCB).btsx = 0, (PCB).drt = -1; | |
1550 do { | |
1551 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
1552 (PCB).ssx--; | |
1553 ag_track(); | |
1554 ag_ra(); | |
1555 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
1556 (PCB).ssx++; | |
1557 (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1558 (PCB).la_ptr++; | |
1559 if (ag_key_index[(PCB).sn]) { | |
1560 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1561 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1562 if (ag_ch <= 255) { | |
1563 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1564 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1565 } | |
1566 } | |
1567 } | |
1568 while ((PCB).token_number == (cf_token_type) ag_t); | |
1569 (PCB).la_ptr = (PCB).pointer; | |
1570 return 1; | |
1571 } | |
1572 | |
1573 static int ag_action_3_r_proc(void) { | |
1574 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1575 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1576 (PCB).btsx = 0, (PCB).drt = -1; | |
1577 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1578 ag_ra(); | |
1579 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1580 } | |
1581 | |
1582 static int ag_action_3_s_proc(void) { | |
1583 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1584 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1585 (PCB).btsx = 0, (PCB).drt = -1; | |
1586 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1587 ag_ra(); | |
1588 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1589 } | |
1590 | |
1591 static int ag_action_4_r_proc(void) { | |
1592 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1593 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1594 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1595 return 1; | |
1596 } | |
1597 | |
1598 static int ag_action_2_proc(void) { | |
1599 (PCB).btsx = 0, (PCB).drt = -1; | |
1600 if ((PCB).ssx >= 128) { | |
1601 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
1602 PARSER_STACK_OVERFLOW; | |
1603 } | |
1604 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
1605 GET_CONTEXT; | |
1606 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1607 (PCB).ssx++; | |
1608 (PCB).sn = (PCB).ag_ap; | |
1609 ag_track(); | |
1610 return 0; | |
1611 } | |
1612 | |
1613 static int ag_action_9_proc(void) { | |
1614 if ((PCB).drt == -1) { | |
1615 (PCB).drt=(PCB).token_number; | |
1616 (PCB).dssx=(PCB).ssx; | |
1617 (PCB).dsn=(PCB).sn; | |
1618 } | |
1619 ag_prot(); | |
1620 (PCB).vs[(PCB).ssx] = ag_null_value; | |
1621 GET_CONTEXT; | |
1622 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1623 (PCB).ssx++; | |
1624 (PCB).sn = (PCB).ag_ap; | |
1625 (PCB).la_ptr = (PCB).pointer; | |
1626 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1627 } | |
1628 | |
1629 static int ag_action_2_r_proc(void) { | |
1630 (PCB).ssx++; | |
1631 (PCB).sn = (PCB).ag_ap; | |
1632 return 0; | |
1633 } | |
1634 | |
1635 static int ag_action_7_proc(void) { | |
1636 --(PCB).ssx; | |
1637 (PCB).la_ptr = (PCB).pointer; | |
1638 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1639 return 0; | |
1640 } | |
1641 | |
1642 static int ag_action_1_proc(void) { | |
1643 ag_track(); | |
1644 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1645 return 0; | |
1646 } | |
1647 | |
1648 static int ag_action_1_r_proc(void) { | |
1649 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1650 return 0; | |
1651 } | |
1652 | |
1653 static int ag_action_1_s_proc(void) { | |
1654 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1655 return 0; | |
1656 } | |
1657 | |
1658 static int ag_action_4_proc(void) { | |
1659 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1660 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1661 (PCB).btsx = 0, (PCB).drt = -1; | |
1662 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
1663 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1664 else GET_CONTEXT; | |
1665 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1666 ag_track(); | |
1667 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1668 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1669 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1670 do { | |
1671 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1672 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1673 else ag_t2 = ag_tx; | |
1674 } while (ag_t1 < ag_t2); | |
1675 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
1676 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
1677 REDUCTION_TOKEN_ERROR; break;} | |
1678 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1679 if ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break; | |
1680 } | |
1681 return 0; | |
1682 } | |
1683 | |
1684 static int ag_action_3_proc(void) { | |
1685 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1686 (PCB).btsx = 0, (PCB).drt = -1; | |
1687 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
1688 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1689 else GET_CONTEXT; | |
1690 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1691 ag_track(); | |
1692 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1693 ag_ra(); | |
1694 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1695 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1696 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1697 do { | |
1698 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1699 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1700 else ag_t2 = ag_tx; | |
1701 } while (ag_t1 < ag_t2); | |
1702 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
1703 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
1704 REDUCTION_TOKEN_ERROR; break;} | |
1705 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1706 if ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break; | |
1707 } | |
1708 return 0; | |
1709 } | |
1710 | |
1711 static int ag_action_8_proc(void) { | |
1712 ag_undo(); | |
1713 (PCB).la_ptr = (PCB).pointer; | |
1714 ag_auto_resynch(); | |
1715 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1716 } | |
1717 | |
1718 static int ag_action_5_proc(void) { | |
1719 int ag_sd = ag_fl[(PCB).ag_ap]; | |
1720 (PCB).btsx = 0, (PCB).drt = -1; | |
1721 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1722 else { | |
1723 GET_CONTEXT; | |
1724 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1725 } | |
1726 (PCB).la_ptr = (PCB).pointer; | |
1727 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1728 ag_ra(); | |
1729 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1730 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1731 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1732 do { | |
1733 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1734 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1735 else ag_t2 = ag_tx; | |
1736 } while (ag_t1 < ag_t2); | |
1737 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
1738 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
1739 REDUCTION_TOKEN_ERROR; break;} | |
1740 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1741 if ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break; | |
1742 } | |
1743 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1744 } | |
1745 | |
1746 static int ag_action_6_proc(void) { | |
1747 int ag_sd = ag_fl[(PCB).ag_ap]; | |
1748 (PCB).reduction_token = (cf_token_type) ag_ptt[(PCB).ag_ap]; | |
1749 if ((PCB).drt == -1) { | |
1750 (PCB).drt=(PCB).token_number; | |
1751 (PCB).dssx=(PCB).ssx; | |
1752 (PCB).dsn=(PCB).sn; | |
1753 } | |
1754 if (ag_sd) { | |
1755 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1756 } | |
1757 else { | |
1758 ag_prot(); | |
1759 (PCB).vs[(PCB).ssx] = ag_null_value; | |
1760 GET_CONTEXT; | |
1761 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1762 } | |
1763 (PCB).la_ptr = (PCB).pointer; | |
1764 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1765 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1766 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1767 do { | |
1768 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1769 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1770 else ag_t2 = ag_tx; | |
1771 } while (ag_t1 < ag_t2); | |
1772 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
1773 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
1774 REDUCTION_TOKEN_ERROR; break;} | |
1775 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1776 if ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break; | |
1777 } | |
1778 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1779 } | |
1780 | |
1781 | |
1782 static void ag_check_depth(int ag_fl) { | |
1783 int ag_sx = (PCB).ssx - ag_fl; | |
1784 if ((PCB).ag_error_depth && ag_sx < (PCB).ag_tmp_depth) (PCB).ag_tmp_depth = ag_sx; | |
1785 } | |
1786 | |
1787 static int ag_action_3_er_proc(void) { | |
1788 ag_check_depth(ag_fl[(PCB).ag_ap] - 1); | |
1789 return ag_action_4_r_proc(); | |
1790 } | |
1791 | |
1792 static int ag_action_2_e_proc(void) { | |
1793 ag_action_2_proc(); | |
1794 (PCB).ag_min_depth = (PCB).ag_tmp_depth; | |
1795 return 0; | |
1796 } | |
1797 | |
1798 static int ag_action_4_e_proc(void) { | |
1799 ag_check_depth(ag_fl[(PCB).ag_ap] - 1); | |
1800 (PCB).ag_min_depth = (PCB).ag_tmp_depth; | |
1801 return ag_action_4_proc(); | |
1802 } | |
1803 | |
1804 static int ag_action_6_e_proc(void) { | |
1805 ag_check_depth(ag_fl[(PCB).ag_ap]); | |
1806 return ag_action_6_proc(); | |
1807 } | |
1808 | |
1809 static int ag_action_11_e_proc(void) { | |
1810 return ag_action_10_proc(); | |
1811 } | |
1812 | |
1813 static int (*ag_r_procs_error[])(void) = { | |
1814 ag_action_1_r_proc, | |
1815 ag_action_2_r_proc, | |
1816 ag_action_3_er_proc, | |
1817 ag_action_3_er_proc | |
1818 }; | |
1819 | |
1820 static int (*ag_s_procs_error[])(void) = { | |
1821 ag_action_1_s_proc, | |
1822 ag_action_2_r_proc, | |
1823 ag_action_3_er_proc, | |
1824 ag_action_3_er_proc | |
1825 }; | |
1826 | |
1827 static int (*ag_gt_procs_error[])(void) = { | |
1828 ag_action_1_proc, | |
1829 ag_action_2_e_proc, | |
1830 ag_action_4_e_proc, | |
1831 ag_action_4_e_proc, | |
1832 ag_action_6_e_proc, | |
1833 ag_action_6_e_proc, | |
1834 ag_action_7_proc, | |
1835 ag_action_8_proc, | |
1836 ag_action_9_proc, | |
1837 ag_action_10_proc, | |
1838 ag_action_11_e_proc, | |
1839 ag_action_8_proc | |
1840 }; | |
1841 | |
1842 static void ag_set_error_procs(void) { | |
1843 (PCB).gt_procs = ag_gt_procs_error; | |
1844 (PCB).r_procs = ag_r_procs_error; | |
1845 (PCB).s_procs = ag_s_procs_error; | |
1846 } | |
1847 | |
1848 | |
1849 void init_cf(void) { | |
1850 (PCB).la_ptr = (PCB).pointer; | |
1851 (PCB).gt_procs = ag_gt_procs_scan; | |
1852 (PCB).r_procs = ag_r_procs_scan; | |
1853 (PCB).s_procs = ag_s_procs_scan; | |
1854 (PCB).ag_error_depth = (PCB).ag_min_depth = (PCB).ag_tmp_depth = 0; | |
1855 (PCB).ag_resynch_active = 0; | |
1856 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
1857 (PCB).exit_flag = AG_RUNNING_CODE; | |
1858 (PCB).line = FIRST_LINE; | |
1859 (PCB).column = FIRST_COLUMN; | |
1860 (PCB).btsx = 0, (PCB).drt = -1; | |
1861 } | |
1862 | |
1863 void cf(void) { | |
1864 init_cf(); | |
1865 (PCB).exit_flag = AG_RUNNING_CODE; | |
1866 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1867 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
1868 if (ag_tstt[ag_t1]) { | |
1869 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
1870 (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1871 (PCB).la_ptr++; | |
1872 if (ag_key_index[(PCB).sn]) { | |
1873 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1874 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1875 if (ag_ch <= 255) { | |
1876 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1877 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1878 } | |
1879 } | |
1880 do { | |
1881 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1882 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
1883 ag_t1 = ag_tx + 1; | |
1884 else ag_t2 = ag_tx; | |
1885 } while (ag_t1 < ag_t2); | |
1886 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
1887 ag_t1 = ag_sbe[(PCB).sn]; | |
1888 } | |
1889 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1890 (*(PCB).gt_procs[ag_astt[ag_t1]])(); | |
1891 } | |
1892 } | |
1893 | |
1894 |