comparison tests/agcl/parsifal/good/tcsoff2.c @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1
2 /*
3 * AnaGram, A System for Syntax Directed Programming
4 * File generated by: ...
5 *
6 * AnaGram Parsing Engine
7 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
8 *
9 * This software is provided 'as-is', without any express or implied
10 * warranty. In no event will the authors be held liable for any damages
11 * arising from the use of this software.
12 *
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
16 *
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software
19 * in a product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
24 */
25
26 #ifndef TCSOFF2_H
27 #include "tcsoff2.h"
28 #endif
29
30 #ifndef TCSOFF2_H
31 #error Mismatched header file
32 #endif
33
34 #include <ctype.h>
35 #include <stdio.h>
36
37 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
38 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
39 #define CONTEXT ((PCB).cs[(PCB).ssx])
40
41
42
43 tcsoff2_pcb_type tcsoff2_pcb;
44 #define PCB tcsoff2_pcb
45
46 /* Line -, tcsoff2.syn */
47 int main(void) {
48 int c;
49 do {
50 c = PCB.input_code = getchar();
51 tcsoff2();
52 } while (c != -1);
53 }
54 return 0;
55
56 #ifndef CONVERT_CASE
57
58 static const char agCaseTable[31] = {
59 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
60 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
61 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0,
62 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
63 };
64
65 static int agConvertCase(int c) {
66 if (c >= 'a' && c <= 'z') return c ^= 0x20;
67 if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0];
68 return c;
69 }
70
71 #define CONVERT_CASE(c) agConvertCase(c)
72
73 #endif
74
75
76 #ifndef TAB_SPACING
77 #define TAB_SPACING 8
78 #endif
79
80 #define ag_rp_1() (printf("Input was yes\n"))
81
82 #define ag_rp_2() (printf("Input was no\n"))
83
84 #define ag_rp_3() (printf("input was 'a-n'...\n"))
85
86 #define ag_rp_4() (printf("input was 'O-Z'...\n"))
87
88
89 #define READ_COUNTS
90 #define WRITE_COUNTS
91 #undef V
92 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
93 #undef VS
94 #define VS(i) (PCB).vs[(PCB).ssx + i]
95
96 #ifndef GET_CONTEXT
97 #define GET_CONTEXT CONTEXT = (PCB).input_context
98 #endif
99
100 typedef enum {
101 ag_action_1,
102 ag_action_2,
103 ag_action_3,
104 ag_action_4,
105 ag_action_5,
106 ag_action_6,
107 ag_action_7,
108 ag_action_8,
109 ag_action_9,
110 ag_action_10,
111 ag_action_11,
112 ag_action_12
113 } ag_parser_action;
114
115
116 #ifndef NULL_VALUE_INITIALIZER
117 #define NULL_VALUE_INITIALIZER = 0
118 #endif
119
120 static int const ag_null_value NULL_VALUE_INITIALIZER;
121
122 static const unsigned char ag_rpx[] = {
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 0, 0, 4
125 };
126
127 static const unsigned char ag_key_itt[] = {
128 0
129 };
130
131 static const unsigned short ag_key_pt[] = {
132 0
133 };
134
135 static const unsigned char ag_key_ch[] = {
136 0, 78, 89,255
137 };
138
139 static const unsigned char ag_key_act[] = {
140 0,3,3,4
141 };
142
143 static const unsigned char ag_key_parm[] = {
144 0, 15, 14, 0
145 };
146
147 static const unsigned char ag_key_jmp[] = {
148 0, 0, 2, 0
149 };
150
151 static const unsigned char ag_key_index[] = {
152 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0
153 };
154
155 static const unsigned char ag_key_ends[] = {
156 79,0, 69,83,0,
157 };
158 #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0)
159
160 static const unsigned char ag_tcv[] = {
161 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0,
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
163 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16,
165 16, 16, 16, 16, 16, 16, 16, 16, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
166 18, 18, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
167 16, 16, 16, 16, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 0, 0, 0,
168 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
169 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
170 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
171 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
172 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
173 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
174 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
175 0, 0, 0, 0, 0
176 };
177
178 #ifndef SYNTAX_ERROR
179 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
180 (PCB).error_message, (PCB).line, (PCB).column)
181 #endif
182
183 #ifndef FIRST_LINE
184 #define FIRST_LINE 1
185 #endif
186
187 #ifndef FIRST_COLUMN
188 #define FIRST_COLUMN 1
189 #endif
190
191 #ifndef PARSER_STACK_OVERFLOW
192 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
193 "\nParser stack overflow, line %d, column %d\n",\
194 (PCB).line, (PCB).column);}
195 #endif
196
197 #ifndef REDUCTION_TOKEN_ERROR
198 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
199 "\nReduction token error, line %d, column %d\n", \
200 (PCB).line, (PCB).column);}
201 #endif
202
203
204 typedef enum
205 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
206 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
207
208
209 #ifndef AG_NEWLINE
210 #define AG_NEWLINE 10
211 #endif
212
213 #ifndef AG_RETURN
214 #define AG_RETURN 13
215 #endif
216
217 #ifndef AG_FORMFEED
218 #define AG_FORMFEED 12
219 #endif
220
221 #ifndef AG_TABCHAR
222 #define AG_TABCHAR 9
223 #endif
224
225 static void ag_track(void) {
226 int ag_k = 0;
227 while (ag_k < (PCB).rx) {
228 int ag_ch = (PCB).lab[ag_k++];
229 switch (ag_ch) {
230 case AG_NEWLINE:
231 (PCB).column = 1, (PCB).line++;
232 case AG_RETURN:
233 case AG_FORMFEED:
234 break;
235 case AG_TABCHAR:
236 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
237 break;
238 default:
239 (PCB).column++;
240 }
241 }
242 ag_k = 0;
243 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++];
244 (PCB).fx = ag_k;
245 (PCB).rx = 0;
246 }
247
248
249 static void ag_prot(void) {
250 int ag_k;
251 ag_k = 128 - ++(PCB).btsx;
252 if (ag_k <= (PCB).ssx) {
253 (PCB).exit_flag = AG_STACK_ERROR_CODE;
254 PARSER_STACK_OVERFLOW;
255 return;
256 }
257 (PCB).bts[(PCB).btsx] = (PCB).sn;
258 (PCB).bts[ag_k] = (PCB).ssx;
259 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
260 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
261 }
262
263 static void ag_undo(void) {
264 if ((PCB).drt == -1) return;
265 while ((PCB).btsx) {
266 int ag_k = 128 - (PCB).btsx;
267 (PCB).sn = (PCB).bts[(PCB).btsx--];
268 (PCB).ssx = (PCB).bts[ag_k];
269 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
270 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
271 }
272 (PCB).token_number = (tcsoff2_token_type) (PCB).drt;
273 (PCB).ssx = (PCB).dssx;
274 (PCB).sn = (PCB).dsn;
275 (PCB).drt = -1;
276 }
277
278
279 static const unsigned char ag_tstt[] = {
280 18,16,15,14,13,4,0,1,2,3,5,6,7,8,9,10,11,12,17,19,
281 18,0,
282 16,0,
283 4,0,
284 15,14,0,2,
285 16,15,14,4,0,2,3,5,6,17,
286 18,15,14,4,0,2,3,5,7,19,
287 18,16,15,14,0,2,3,6,7,17,19,
288 18,16,4,0,5,6,7,17,19,
289 13,0,
290 4,0,
291 15,14,0,2,
292 4,0,
293 15,14,0,2,
294 15,14,0,2,
295 4,0,
296 0
297 };
298
299
300 static unsigned const char ag_astt[91] = {
301 1,1,2,2,8,1,7,0,1,1,1,1,1,1,1,1,1,1,1,1,9,4,9,4,9,5,2,2,5,3,1,2,2,1,5,1,1,
302 1,3,1,1,2,2,1,5,1,1,1,3,1,1,1,2,2,5,1,1,3,3,1,1,1,1,1,5,1,3,3,1,1,3,7,9,5,
303 2,2,5,3,9,5,2,2,5,3,2,2,5,3,9,5,11
304 };
305
306
307 static const unsigned char ag_pstt[] = {
308 1,2,28,27,9,3,0,0,4,4,3,6,5,8,7,6,5,9,2,1,
309 33,34,
310 30,31,
311 4,10,
312 28,27,5,2,
313 2,28,27,10,25,11,11,10,16,2,
314 1,28,27,12,24,13,13,12,19,1,
315 1,2,28,27,23,14,14,14,18,2,1,
316 1,2,15,22,15,13,17,2,1,
317 26,9,
318 4,12,
319 28,27,8,2,
320 4,11,
321 28,27,7,2,
322 28,27,6,2,
323 4,9,
324 0
325 };
326
327
328 static const unsigned char ag_sbt[] = {
329 0, 20, 22, 24, 26, 30, 40, 50, 61, 70, 72, 74, 78, 80,
330 84, 88, 90
331 };
332
333
334 static const unsigned char ag_sbe[] = {
335 6, 21, 23, 25, 28, 34, 44, 54, 64, 71, 73, 76, 79, 82,
336 86, 89, 90
337 };
338
339
340 static const unsigned char ag_fl[] = {
341 1,1,2,1,2,1,2,2,2,2,1,2,2,2,2,1,2,2,2,2,1,0,1,1,1,1,2,1,1,1,2,1,1,2,1
342 };
343
344 static const unsigned char ag_ptt[] = {
345 0, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11,
346 11, 11, 11, 12, 12, 12, 12, 12, 1, 2, 2, 17, 17, 6, 19, 19, 7
347 };
348
349
350 static void ag_ra(void)
351 {
352 switch(ag_rpx[(PCB).ag_ap]) {
353 case 1: ag_rp_1(); break;
354 case 2: ag_rp_2(); break;
355 case 3: ag_rp_3(); break;
356 case 4: ag_rp_4(); break;
357 }
358 }
359
360 #define TOKEN_NAMES tcsoff2_token_names
361 const char *const tcsoff2_token_names[20] = {
362 "grammar",
363 "grammar",
364 "word",
365 "",
366 "eol",
367 "",
368 "string 1",
369 "string 2",
370 "",
371 "",
372 "",
373 "",
374 "",
375 "eof",
376 "\"YES\"",
377 "\"NO\"",
378 "",
379 "",
380 "",
381 "",
382
383 };
384
385 #ifndef MISSING_FORMAT
386 #define MISSING_FORMAT "Missing %s"
387 #endif
388 #ifndef UNEXPECTED_FORMAT
389 #define UNEXPECTED_FORMAT "Unexpected %s"
390 #endif
391 #ifndef UNNAMED_TOKEN
392 #define UNNAMED_TOKEN "input"
393 #endif
394
395
396 static void ag_diagnose(void) {
397 int ag_snd = (PCB).sn;
398 int ag_k = ag_sbt[ag_snd];
399
400 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) {
401 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
402 }
403 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8
404 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1
405 && *TOKEN_NAMES[ag_tstt[ag_k]]) {
406 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
407 }
408 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
409 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]);
410 }
411 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') {
412 char buf[20];
413 sprintf(buf, "\'%c\'", (char) (*(PCB).lab));
414 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf);
415 }
416 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN);
417 (PCB).error_message = (PCB).ag_msg;
418
419
420 }
421 static int ag_action_1_r_proc(void);
422 static int ag_action_2_r_proc(void);
423 static int ag_action_3_r_proc(void);
424 static int ag_action_4_r_proc(void);
425 static int ag_action_1_s_proc(void);
426 static int ag_action_3_s_proc(void);
427 static int ag_action_1_proc(void);
428 static int ag_action_2_proc(void);
429 static int ag_action_3_proc(void);
430 static int ag_action_4_proc(void);
431 static int ag_action_5_proc(void);
432 static int ag_action_6_proc(void);
433 static int ag_action_7_proc(void);
434 static int ag_action_8_proc(void);
435 static int ag_action_9_proc(void);
436 static int ag_action_10_proc(void);
437 static int ag_action_11_proc(void);
438 static int ag_action_8_proc(void);
439
440
441 static int (*const ag_r_procs_scan[])(void) = {
442 ag_action_1_r_proc,
443 ag_action_2_r_proc,
444 ag_action_3_r_proc,
445 ag_action_4_r_proc
446 };
447
448 static int (*const ag_s_procs_scan[])(void) = {
449 ag_action_1_s_proc,
450 ag_action_2_r_proc,
451 ag_action_3_s_proc,
452 ag_action_4_r_proc
453 };
454
455 static int (*const ag_gt_procs_scan[])(void) = {
456 ag_action_1_proc,
457 ag_action_2_proc,
458 ag_action_3_proc,
459 ag_action_4_proc,
460 ag_action_5_proc,
461 ag_action_6_proc,
462 ag_action_7_proc,
463 ag_action_8_proc,
464 ag_action_9_proc,
465 ag_action_10_proc,
466 ag_action_11_proc,
467 ag_action_8_proc
468 };
469
470
471 static int ag_action_10_proc(void) {
472 (PCB).btsx = 0, (PCB).drt = -1;
473 ag_track();
474 return 0;
475 }
476
477 static int ag_action_11_proc(void) {
478 (PCB).btsx = 0, (PCB).drt = -1;
479 (PCB).vs[(PCB).ssx] = *(PCB).lab;
480 (PCB).ssx--;
481 ag_ra();
482 (PCB).ssx++;
483 ag_track();
484 return 0;
485 }
486
487 static int ag_action_3_r_proc(void) {
488 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
489 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
490 (PCB).btsx = 0, (PCB).drt = -1;
491 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
492 ag_ra();
493 return (PCB).exit_flag == AG_RUNNING_CODE;
494 }
495
496 static int ag_action_3_s_proc(void) {
497 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
498 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
499 (PCB).btsx = 0, (PCB).drt = -1;
500 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
501 ag_ra();
502 return (PCB).exit_flag == AG_RUNNING_CODE;
503 }
504
505 static int ag_action_4_r_proc(void) {
506 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
507 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
508 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
509 return 1;
510 }
511
512 static int ag_action_2_proc(void) {
513 (PCB).btsx = 0, (PCB).drt = -1;
514 if ((PCB).ssx >= 128) {
515 (PCB).exit_flag = AG_STACK_ERROR_CODE;
516 PARSER_STACK_OVERFLOW;
517 }
518 (PCB).vs[(PCB).ssx] = *(PCB).lab;
519 (PCB).ss[(PCB).ssx] = (PCB).sn;
520 (PCB).ssx++;
521 (PCB).sn = (PCB).ag_ap;
522 ag_track();
523 return 0;
524 }
525
526 static int ag_action_9_proc(void) {
527 if ((PCB).drt == -1) {
528 (PCB).drt=(PCB).token_number;
529 (PCB).dssx=(PCB).ssx;
530 (PCB).dsn=(PCB).sn;
531 }
532 ag_prot();
533 (PCB).ss[(PCB).ssx] = (PCB).sn;
534 (PCB).ssx++;
535 (PCB).sn = (PCB).ag_ap;
536 (PCB).rx = 0;
537 return (PCB).exit_flag == AG_RUNNING_CODE;
538 }
539
540 static int ag_action_2_r_proc(void) {
541 (PCB).ssx++;
542 (PCB).sn = (PCB).ag_ap;
543 return 0;
544 }
545
546 static int ag_action_7_proc(void) {
547 --(PCB).ssx;
548 (PCB).exit_flag = AG_SUCCESS_CODE;
549 (PCB).rx = 0;
550 return 0;
551 }
552
553 static int ag_action_1_proc(void) {
554 (PCB).exit_flag = AG_SUCCESS_CODE;
555 ag_track();
556 return 0;
557 }
558
559 static int ag_action_1_r_proc(void) {
560 (PCB).exit_flag = AG_SUCCESS_CODE;
561 return 0;
562 }
563
564 static int ag_action_1_s_proc(void) {
565 (PCB).exit_flag = AG_SUCCESS_CODE;
566 return 0;
567 }
568
569 static int ag_action_4_proc(void) {
570 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
571 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
572 (PCB).btsx = 0, (PCB).drt = -1;
573 (PCB).vs[(PCB).ssx] = *(PCB).lab;
574 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
575 else (PCB).ss[(PCB).ssx] = (PCB).sn;
576 ag_track();
577 while ((PCB).exit_flag == AG_RUNNING_CODE) {
578 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
579 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
580 do {
581 unsigned ag_tx = (ag_t1 + ag_t2)/2;
582 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
583 else ag_t2 = ag_tx;
584 } while (ag_t1 < ag_t2);
585 (PCB).ag_ap = ag_pstt[ag_t1];
586 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
587 }
588 return 0;
589 }
590
591 static int ag_action_3_proc(void) {
592 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
593 (PCB).btsx = 0, (PCB).drt = -1;
594 (PCB).vs[(PCB).ssx] = *(PCB).lab;
595 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
596 else (PCB).ss[(PCB).ssx] = (PCB).sn;
597 ag_track();
598 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
599 ag_ra();
600 while ((PCB).exit_flag == AG_RUNNING_CODE) {
601 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
602 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
603 do {
604 unsigned ag_tx = (ag_t1 + ag_t2)/2;
605 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
606 else ag_t2 = ag_tx;
607 } while (ag_t1 < ag_t2);
608 (PCB).ag_ap = ag_pstt[ag_t1];
609 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
610 }
611 return 0;
612 }
613
614 static int ag_action_8_proc(void) {
615 ag_undo();
616 (PCB).rx = 0;
617 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
618 ag_diagnose();
619 SYNTAX_ERROR;
620 {(PCB).rx = 1; ag_track();}
621 return (PCB).exit_flag == AG_RUNNING_CODE;
622 }
623
624 static int ag_action_5_proc(void) {
625 int ag_sd = ag_fl[(PCB).ag_ap];
626 (PCB).btsx = 0, (PCB).drt = -1;
627 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
628 else {
629 (PCB).ss[(PCB).ssx] = (PCB).sn;
630 }
631 (PCB).rx = 0;
632 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
633 ag_ra();
634 while ((PCB).exit_flag == AG_RUNNING_CODE) {
635 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
636 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
637 do {
638 unsigned ag_tx = (ag_t1 + ag_t2)/2;
639 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
640 else ag_t2 = ag_tx;
641 } while (ag_t1 < ag_t2);
642 (PCB).ag_ap = ag_pstt[ag_t1];
643 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
644 }
645 return (PCB).exit_flag == AG_RUNNING_CODE;
646 }
647
648 static int ag_action_6_proc(void) {
649 int ag_sd = ag_fl[(PCB).ag_ap];
650 (PCB).reduction_token = (tcsoff2_token_type) ag_ptt[(PCB).ag_ap];
651 if ((PCB).drt == -1) {
652 (PCB).drt=(PCB).token_number;
653 (PCB).dssx=(PCB).ssx;
654 (PCB).dsn=(PCB).sn;
655 }
656 if (ag_sd) {
657 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
658 }
659 else {
660 ag_prot();
661 (PCB).vs[(PCB).ssx] = ag_null_value;
662 (PCB).ss[(PCB).ssx] = (PCB).sn;
663 }
664 (PCB).rx = 0;
665 while ((PCB).exit_flag == AG_RUNNING_CODE) {
666 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
667 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
668 do {
669 unsigned ag_tx = (ag_t1 + ag_t2)/2;
670 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
671 else ag_t2 = ag_tx;
672 } while (ag_t1 < ag_t2);
673 (PCB).ag_ap = ag_pstt[ag_t1];
674 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
675 }
676 return (PCB).exit_flag == AG_RUNNING_CODE;
677 }
678
679
680 void init_tcsoff2(void) {
681 unsigned ag_t1;
682 ag_t1 = 0;
683 (PCB).rx = (PCB).fx = 0;
684 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
685 (PCB).exit_flag = AG_RUNNING_CODE;
686 (PCB).key_sp = NULL;
687 (PCB).key_state = 0;
688 (PCB).line = FIRST_LINE;
689 (PCB).column = FIRST_COLUMN;
690 (PCB).btsx = 0, (PCB).drt = -1;
691 while (ag_tstt[ag_t1] == 0) {
692 (PCB).ag_ap = ag_pstt[ag_t1];
693 (ag_gt_procs_scan[ag_astt[ag_t1]])();
694 ag_t1 = ag_sbt[(PCB).sn];
695 }
696 }
697
698 void tcsoff2(void) {
699 (PCB).lab[(PCB).fx++] = (PCB).input_code;
700 while ((PCB).exit_flag == AG_RUNNING_CODE) {
701 while (1) {
702 const unsigned char *ag_p;
703 int ag_ch;
704 if ((PCB).rx >= (PCB).fx) return;
705 ag_ch = CONVERT_CASE((PCB).lab[(PCB).rx++]);
706 if ((PCB).key_sp) {
707 if (ag_ch != *(PCB).key_sp++) {
708 (PCB).rx = (PCB).save_index;
709 (PCB).key_sp = NULL;
710 (PCB).key_state = 0;
711 break;
712 } else if (*(PCB).key_sp) continue;
713 if (ag_key_act[(PCB).key_state] == ag_cf_end_key) {
714 int ag_k1;
715 int ag_k2;
716 if ((PCB).rx >= (PCB).fx) {
717 (PCB).rx--;
718 (PCB).key_sp--;
719 return;
720 }
721 (PCB).key_sp = NULL;
722 ag_k1 = ag_key_parm[(PCB).key_state];
723 ag_k2 = ag_key_pt[ag_k1];
724 if (ag_key_itt[ag_k2 + CONVERT_CASE((PCB).lab[(PCB).rx])])
725 (PCB).rx = (PCB).save_index;
726 else {
727 (PCB).token_number = (tcsoff2_token_type) ag_key_pt[ag_k1+1];
728 (PCB).key_state = 0;
729 }
730 break;
731 }
732 else {
733 (PCB).token_number = (tcsoff2_token_type) ag_key_parm[(PCB).key_state];
734 (PCB).key_state = 0;
735 (PCB).key_sp = NULL;
736 }
737 break;
738 }
739 if ((PCB).key_state == 0) {
740 (PCB).token_number = (tcsoff2_token_type) AG_TCV(ag_ch);
741 if (((PCB).key_state = ag_key_index[(PCB).sn]) == 0) break;
742 (PCB).save_index = 1;
743 }
744 ag_p = &ag_key_ch[(PCB).key_state];
745 if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++;
746 if (*ag_p == ag_ch) {
747 (PCB).key_state = (int)(ag_p - ag_key_ch);
748 switch (ag_key_act[(PCB).key_state]) {
749 case ag_cf_set_key: {
750 int ag_k1;
751 int ag_k2;
752 if ((PCB).rx >= (PCB).fx) {
753 (PCB).rx--;
754 return;
755 }
756 ag_k1 = ag_key_parm[(PCB).key_state];
757 ag_k2 = ag_key_pt[ag_k1];
758 (PCB).key_state = ag_key_jmp[(PCB).key_state];
759 if (ag_key_itt[ag_k2 + CONVERT_CASE((PCB).lab[(PCB).rx])]) continue;
760 (PCB).save_index = (PCB).rx;
761 (PCB).token_number = (tcsoff2_token_type) ag_key_pt[ag_k1+1];
762 continue;
763 }
764 case ag_set_key:
765 (PCB).save_index = (PCB).rx;
766 (PCB).token_number = (tcsoff2_token_type) ag_key_parm[(PCB).key_state];
767 case ag_jmp_key:
768 (PCB).key_state = ag_key_jmp[(PCB).key_state];
769 continue;
770 case ag_cf_end_key:
771 case ag_end_key:
772 (PCB).key_sp = ag_key_ends + ag_key_jmp[(PCB).key_state];
773 continue;
774 case ag_accept_key:
775 (PCB).token_number = (tcsoff2_token_type) ag_key_parm[(PCB).key_state];
776 (PCB).key_state = 0;
777 break;
778 case ag_cf_accept_key: {
779 int ag_k1;
780 int ag_k2;
781 if ((PCB).rx >= (PCB).fx) {
782 (PCB).rx--;
783 return;
784 }
785 ag_k1 = ag_key_parm[(PCB).key_state];
786 ag_k2 = ag_key_pt[ag_k1];
787 if (ag_key_itt[ag_k2 + CONVERT_CASE((PCB).lab[(PCB).rx])])
788 (PCB).rx = (PCB).save_index;
789 else {
790 (PCB).token_number = (tcsoff2_token_type) ag_key_pt[ag_k1+1];
791 (PCB).key_state = 0;
792 }
793 break;
794 }
795 }
796 break;
797 } else {
798 (PCB).rx = (PCB).save_index;
799 (PCB).key_state = 0;
800 break;
801 }
802 }
803
804 {
805 unsigned ag_t1 = ag_sbt[(PCB).sn];
806 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
807 do {
808 unsigned ag_tx = (ag_t1 + ag_t2)/2;
809 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
810 ag_t1 = ag_tx + 1;
811 else ag_t2 = ag_tx;
812 } while (ag_t1 < ag_t2);
813 if (ag_tstt[ag_t1] != (PCB).token_number) ag_t1 = ag_sbe[(PCB).sn];
814 (PCB).ag_ap = ag_pstt[ag_t1];
815 (ag_gt_procs_scan[ag_astt[ag_t1]])();
816 }
817 }
818 }
819
820