comparison tests/agcl/examples/good/fc2.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 FC2_H
27 #include "fc2.h"
28 #endif
29
30 #ifndef FC2_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 fc2_pcb_type fc2_pcb;
44 #define PCB fc2_pcb
45
46 #ifndef CONVERT_CASE
47 #define CONVERT_CASE(c) (c)
48 #endif
49 #ifndef TAB_SPACING
50 #define TAB_SPACING 8
51 #endif
52
53 static void ag_rp_1(int n) {
54 /* Line -, fc2.syn */
55 /* P2 */
56 printf("%d\370F = %d\370C\n",9*n/5 + 32,n);
57
58 }
59
60 static void ag_rp_2(int n) {
61 /* Line -, fc2.syn */
62 /* P3 */
63 printf("%d\370F = %d\370C\n",n,5*(n-32)/9);
64
65 }
66
67 #define ag_rp_3(n) (-n)
68
69 #define ag_rp_4(n) (n)
70
71 #define ag_rp_5(d) (d-'0')
72
73 #define ag_rp_6(n, d) (10*n+d-'0')
74
75
76 #define READ_COUNTS
77 #define WRITE_COUNTS
78 #undef V
79 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
80 #undef VS
81 #define VS(i) (PCB).vs[(PCB).ssx + i]
82
83 #ifndef GET_CONTEXT
84 #define GET_CONTEXT CONTEXT = (PCB).input_context
85 #endif
86
87 typedef enum {
88 ag_action_1,
89 ag_action_2,
90 ag_action_3,
91 ag_action_4,
92 ag_action_5,
93 ag_action_6,
94 ag_action_7,
95 ag_action_8,
96 ag_action_9,
97 ag_action_10,
98 ag_action_11,
99 ag_action_12
100 } ag_parser_action;
101
102
103 #ifndef NULL_VALUE_INITIALIZER
104 #define NULL_VALUE_INITIALIZER = 0
105 #endif
106
107 static int const ag_null_value NULL_VALUE_INITIALIZER;
108
109 static const unsigned char ag_rpx[] = {
110 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 4, 5, 6
111 };
112 #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0)
113
114 static const unsigned char ag_tcv[] = {
115 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 12, 0, 0, 16, 16, 16, 16, 16,
118 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 10,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 10, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0
130 };
131
132 #ifndef SYNTAX_ERROR
133 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
134 (PCB).error_message, (PCB).line, (PCB).column)
135 #endif
136
137 #ifndef FIRST_LINE
138 #define FIRST_LINE 1
139 #endif
140
141 #ifndef FIRST_COLUMN
142 #define FIRST_COLUMN 1
143 #endif
144
145 #ifndef PARSER_STACK_OVERFLOW
146 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
147 "\nParser stack overflow, line %d, column %d\n",\
148 (PCB).line, (PCB).column);}
149 #endif
150
151 #ifndef REDUCTION_TOKEN_ERROR
152 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
153 "\nReduction token error, line %d, column %d\n", \
154 (PCB).line, (PCB).column);}
155 #endif
156
157
158 #ifndef GET_INPUT
159 #define GET_INPUT ((PCB).input_code = getchar())
160 #endif
161
162
163 #ifndef AG_NEWLINE
164 #define AG_NEWLINE 10
165 #endif
166
167 #ifndef AG_RETURN
168 #define AG_RETURN 13
169 #endif
170
171 #ifndef AG_FORMFEED
172 #define AG_FORMFEED 12
173 #endif
174
175 #ifndef AG_TABCHAR
176 #define AG_TABCHAR 9
177 #endif
178
179 static void ag_track(void) {
180 switch ((PCB).input_code) {
181 case AG_NEWLINE:
182 (PCB).column = 1, (PCB).line++;
183 case AG_RETURN:
184 case AG_FORMFEED:
185 break;
186 case AG_TABCHAR:
187 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
188 break;
189 default:
190 (PCB).column++;
191 }
192 (PCB).read_flag = 1;
193 }
194
195
196 static void ag_prot(void) {
197 int ag_k;
198 ag_k = 128 - ++(PCB).btsx;
199 if (ag_k <= (PCB).ssx) {
200 (PCB).exit_flag = AG_STACK_ERROR_CODE;
201 PARSER_STACK_OVERFLOW;
202 return;
203 }
204 (PCB).bts[(PCB).btsx] = (PCB).sn;
205 (PCB).bts[ag_k] = (PCB).ssx;
206 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
207 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
208 }
209
210 static void ag_undo(void) {
211 if ((PCB).drt == -1) return;
212 while ((PCB).btsx) {
213 int ag_k = 128 - (PCB).btsx;
214 (PCB).sn = (PCB).bts[(PCB).btsx--];
215 (PCB).ssx = (PCB).bts[ag_k];
216 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
217 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
218 }
219 (PCB).token_number = (fc2_token_type) (PCB).drt;
220 (PCB).ssx = (PCB).dssx;
221 (PCB).sn = (PCB).dsn;
222 (PCB).drt = -1;
223 }
224
225
226 static const unsigned char ag_tstt[] = {
227 16,14,12,11,7,0,1,2,4,5,6,8,15,
228 16,0,
229 16,0,13,
230 16,0,13,
231 3,0,
232 10,9,0,
233 3,0,
234 16,14,12,7,0,
235 16,14,12,11,7,0,2,4,8,15,
236 7,0,
237 16,10,9,0,
238 16,10,9,0,
239 16,10,9,0,
240 3,0,
241 3,0,
242 16,14,12,7,0,
243 16,14,12,7,0,
244 16,10,9,0,
245
246 };
247
248
249 static unsigned const char ag_astt[75] = {
250 5,1,1,1,5,7,0,1,1,1,1,1,1,5,7,1,7,1,1,7,1,5,7,1,1,7,1,7,5,5,5,5,7,5,1,1,1,
251 5,7,1,1,1,1,3,7,4,4,4,7,1,4,4,7,1,4,4,7,4,7,4,7,5,5,5,5,7,5,5,5,5,7,4,4,4,
252 7
253 };
254
255
256 static const unsigned char ag_pstt[] = {
257 11,1,3,4,4,0,0,6,7,8,9,5,2,
258 12,1,
259 10,2,11,
260 10,3,12,
261 9,4,
262 13,14,5,
263 15,6,
264 2,2,2,2,7,
265 11,1,3,4,5,8,6,16,5,2,
266 6,9,
267 14,14,14,10,
268 17,13,13,11,
269 17,10,10,12,
270 8,13,
271 7,14,
272 1,1,1,1,15,
273 3,3,3,3,16,
274 15,15,15,17,
275
276 };
277
278
279 static const unsigned char ag_sbt[] = {
280 0, 13, 15, 18, 21, 23, 26, 28, 33, 43, 45, 49, 53, 57,
281 59, 61, 66, 71, 75
282 };
283
284
285 static const unsigned char ag_sbe[] = {
286 5, 14, 16, 19, 22, 25, 27, 32, 38, 44, 48, 52, 56, 58,
287 60, 65, 70, 74, 75
288 };
289
290
291 static const unsigned char ag_fl[] = {
292 1,2,1,2,0,1,2,2,2,1,2,0,1,2,1,2
293 };
294
295 static const unsigned char ag_ptt[] = {
296 0, 4, 5, 5, 6, 6, 1, 2, 2, 2, 8, 15, 15, 8, 13, 13
297 };
298
299
300 static void ag_ra(void)
301 {
302 switch(ag_rpx[(PCB).ag_ap]) {
303 case 1: ag_rp_1(VS(0)); break;
304 case 2: ag_rp_2(VS(0)); break;
305 case 3: VS(0) = ag_rp_3(VS(1)); break;
306 case 4: VS(0) = ag_rp_4(VS(1)); break;
307 case 5: VS(0) = ag_rp_5(VS(0)); break;
308 case 6: VS(0) = ag_rp_6(VS(0), VS(1)); break;
309 }
310 }
311
312 #define TOKEN_NAMES fc2_token_names
313 const char *const fc2_token_names[17] = {
314 "grammar",
315 "grammar",
316 "temperature",
317 "'\\n'",
318 "",
319 "",
320 "",
321 "eof",
322 "number",
323 "",
324 "",
325 "error",
326 "'-'",
327 "integer",
328 "'+'",
329 "",
330 "",
331
332 };
333
334 #ifndef MISSING_FORMAT
335 #define MISSING_FORMAT "Missing %s"
336 #endif
337 #ifndef UNEXPECTED_FORMAT
338 #define UNEXPECTED_FORMAT "Unexpected %s"
339 #endif
340 #ifndef UNNAMED_TOKEN
341 #define UNNAMED_TOKEN "input"
342 #endif
343
344
345 static void ag_diagnose(void) {
346 int ag_snd = (PCB).sn;
347 int ag_k = ag_sbt[ag_snd];
348
349 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) {
350 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
351 }
352 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8
353 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1
354 && *TOKEN_NAMES[ag_tstt[ag_k]]) {
355 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
356 }
357 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
358 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]);
359 }
360 else if (isprint(((PCB).input_code)) && ((PCB).input_code) != '\\') {
361 char buf[20];
362 sprintf(buf, "\'%c\'", (char) ((PCB).input_code));
363 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf);
364 }
365 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN);
366 (PCB).error_message = (PCB).ag_msg;
367
368
369 }
370 static int ag_action_1_r_proc(void);
371 static int ag_action_2_r_proc(void);
372 static int ag_action_3_r_proc(void);
373 static int ag_action_4_r_proc(void);
374 static int ag_action_1_s_proc(void);
375 static int ag_action_3_s_proc(void);
376 static int ag_action_1_proc(void);
377 static int ag_action_2_proc(void);
378 static int ag_action_3_proc(void);
379 static int ag_action_4_proc(void);
380 static int ag_action_5_proc(void);
381 static int ag_action_6_proc(void);
382 static int ag_action_7_proc(void);
383 static int ag_action_8_proc(void);
384 static int ag_action_9_proc(void);
385 static int ag_action_10_proc(void);
386 static int ag_action_11_proc(void);
387 static int ag_action_8_proc(void);
388
389
390 static int (*const ag_r_procs_scan[])(void) = {
391 ag_action_1_r_proc,
392 ag_action_2_r_proc,
393 ag_action_3_r_proc,
394 ag_action_4_r_proc
395 };
396
397 static int (*const ag_s_procs_scan[])(void) = {
398 ag_action_1_s_proc,
399 ag_action_2_r_proc,
400 ag_action_3_s_proc,
401 ag_action_4_r_proc
402 };
403
404 static int (*const ag_gt_procs_scan[])(void) = {
405 ag_action_1_proc,
406 ag_action_2_proc,
407 ag_action_3_proc,
408 ag_action_4_proc,
409 ag_action_5_proc,
410 ag_action_6_proc,
411 ag_action_7_proc,
412 ag_action_8_proc,
413 ag_action_9_proc,
414 ag_action_10_proc,
415 ag_action_11_proc,
416 ag_action_8_proc
417 };
418
419
420 static int ag_action_1_er_proc(void);
421 static int ag_action_2_er_proc(void);
422 static int ag_action_3_er_proc(void);
423 static int ag_action_4_er_proc(void);
424
425 static int (*const ag_er_procs_scan[])(void) = {
426 ag_action_1_er_proc,
427 ag_action_2_er_proc,
428 ag_action_3_er_proc,
429 ag_action_4_er_proc
430 };
431
432
433 static void ag_error_resynch(void) {
434 int ag_k;
435 int ag_ssx = (PCB).ssx;
436
437 ag_diagnose();
438 SYNTAX_ERROR;
439 if ((PCB).exit_flag != AG_RUNNING_CODE) return;
440 while (1) {
441 ag_k = ag_sbt[(PCB).sn];
442 while (ag_tstt[ag_k] != 11 && ag_tstt[ag_k]) ag_k++;
443 if (ag_tstt[ag_k] || (PCB).ssx == 0) break;
444 (PCB).sn = (PCB).ss[--(PCB).ssx];
445 }
446 if (ag_tstt[ag_k] == 0) {
447 (PCB).sn = PCB.ss[(PCB).ssx = ag_ssx];
448 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
449 return;
450 }
451 ag_k = ag_sbt[(PCB).sn];
452 while (ag_tstt[ag_k] != 11 && ag_tstt[ag_k]) ag_k++;
453 (PCB).ag_ap = ag_pstt[ag_k];
454 (ag_er_procs_scan[ag_astt[ag_k]])();
455 while (1) {
456 ag_k = ag_sbt[(PCB).sn];
457 while (ag_tstt[ag_k] != (unsigned char) (PCB).token_number && ag_tstt[ag_k])
458 ag_k++;
459 if (ag_tstt[ag_k] && ag_astt[ag_k] != ag_action_10) break;
460 if ((PCB).token_number == 7)
461 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;}
462 ag_track();
463 if ((PCB).read_flag) {
464 (PCB).read_flag = 0;
465 GET_INPUT;
466 };
467 (PCB).token_number = (fc2_token_type) AG_TCV((PCB).input_code);
468 }
469 }
470
471
472 static int ag_action_10_proc(void) {
473 int ag_t = (PCB).token_number;
474 (PCB).btsx = 0, (PCB).drt = -1;
475 do {
476 ag_track();
477 if ((PCB).read_flag) {
478 (PCB).read_flag = 0;
479 GET_INPUT;
480 };
481 (PCB).token_number = (fc2_token_type) AG_TCV((PCB).input_code);
482 } while ((PCB).token_number == (fc2_token_type) ag_t);
483 return 1;
484 }
485
486 static int ag_action_11_proc(void) {
487 int ag_t = (PCB).token_number;
488
489 (PCB).btsx = 0, (PCB).drt = -1;
490 do {
491 (PCB).vs[(PCB).ssx] = (PCB).input_code;
492 (PCB).ssx--;
493 ag_track();
494 ag_ra();
495 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
496 (PCB).ssx++;
497 if ((PCB).read_flag) {
498 (PCB).read_flag = 0;
499 GET_INPUT;
500 };
501 (PCB).token_number = (fc2_token_type) AG_TCV((PCB).input_code);
502 }
503 while ((PCB).token_number == (fc2_token_type) ag_t);
504 return 1;
505 }
506
507 static int ag_action_3_r_proc(void) {
508 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
509 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
510 (PCB).btsx = 0, (PCB).drt = -1;
511 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
512 ag_ra();
513 return (PCB).exit_flag == AG_RUNNING_CODE;
514 }
515
516 static int ag_action_3_s_proc(void) {
517 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
518 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
519 (PCB).btsx = 0, (PCB).drt = -1;
520 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
521 ag_ra();
522 return (PCB).exit_flag == AG_RUNNING_CODE;
523 }
524
525 static int ag_action_4_r_proc(void) {
526 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
527 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
528 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
529 return 1;
530 }
531
532 static int ag_action_2_proc(void) {
533 (PCB).btsx = 0, (PCB).drt = -1;
534 if ((PCB).ssx >= 128) {
535 (PCB).exit_flag = AG_STACK_ERROR_CODE;
536 PARSER_STACK_OVERFLOW;
537 }
538 (PCB).vs[(PCB).ssx] = (PCB).input_code;
539 (PCB).ss[(PCB).ssx] = (PCB).sn;
540 (PCB).ssx++;
541 (PCB).sn = (PCB).ag_ap;
542 ag_track();
543 return 0;
544 }
545
546 static int ag_action_9_proc(void) {
547 if ((PCB).drt == -1) {
548 (PCB).drt=(PCB).token_number;
549 (PCB).dssx=(PCB).ssx;
550 (PCB).dsn=(PCB).sn;
551 }
552 ag_prot();
553 (PCB).vs[(PCB).ssx] = ag_null_value;
554 (PCB).ss[(PCB).ssx] = (PCB).sn;
555 (PCB).ssx++;
556 (PCB).sn = (PCB).ag_ap;
557 return (PCB).exit_flag == AG_RUNNING_CODE;
558 }
559
560 static int ag_action_2_r_proc(void) {
561 (PCB).ssx++;
562 (PCB).sn = (PCB).ag_ap;
563 return 0;
564 }
565
566 static int ag_action_7_proc(void) {
567 --(PCB).ssx;
568 (PCB).exit_flag = AG_SUCCESS_CODE;
569 return 0;
570 }
571
572 static int ag_action_1_proc(void) {
573 ag_track();
574 (PCB).exit_flag = AG_SUCCESS_CODE;
575 return 0;
576 }
577
578 static int ag_action_1_r_proc(void) {
579 (PCB).exit_flag = AG_SUCCESS_CODE;
580 return 0;
581 }
582
583 static int ag_action_1_s_proc(void) {
584 (PCB).exit_flag = AG_SUCCESS_CODE;
585 return 0;
586 }
587
588 static int ag_action_4_proc(void) {
589 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
590 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
591 (PCB).btsx = 0, (PCB).drt = -1;
592 (PCB).vs[(PCB).ssx] = (PCB).input_code;
593 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
594 else (PCB).ss[(PCB).ssx] = (PCB).sn;
595 ag_track();
596 while ((PCB).exit_flag == AG_RUNNING_CODE) {
597 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
598 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
599 do {
600 unsigned ag_tx = (ag_t1 + ag_t2)/2;
601 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
602 else ag_t2 = ag_tx;
603 } while (ag_t1 < ag_t2);
604 (PCB).ag_ap = ag_pstt[ag_t1];
605 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
606 }
607 return 0;
608 }
609
610 static int ag_action_3_proc(void) {
611 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
612 (PCB).btsx = 0, (PCB).drt = -1;
613 (PCB).vs[(PCB).ssx] = (PCB).input_code;
614 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
615 else (PCB).ss[(PCB).ssx] = (PCB).sn;
616 ag_track();
617 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
618 ag_ra();
619 while ((PCB).exit_flag == AG_RUNNING_CODE) {
620 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
621 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
622 do {
623 unsigned ag_tx = (ag_t1 + ag_t2)/2;
624 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
625 else ag_t2 = ag_tx;
626 } while (ag_t1 < ag_t2);
627 (PCB).ag_ap = ag_pstt[ag_t1];
628 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
629 }
630 return 0;
631 }
632
633 static int ag_action_8_proc(void) {
634 int ag_k = ag_sbt[(PCB).sn];
635 while (ag_tstt[ag_k] != 11 && ag_tstt[ag_k]) ag_k++;
636 if (ag_tstt[ag_k] == 0) ag_undo();
637 ag_error_resynch();
638 return (PCB).exit_flag == AG_RUNNING_CODE;
639 }
640
641 static int ag_action_5_proc(void) {
642 int ag_sd = ag_fl[(PCB).ag_ap];
643 (PCB).btsx = 0, (PCB).drt = -1;
644 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
645 else {
646 (PCB).ss[(PCB).ssx] = (PCB).sn;
647 }
648 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
649 ag_ra();
650 while ((PCB).exit_flag == AG_RUNNING_CODE) {
651 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
652 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
653 do {
654 unsigned ag_tx = (ag_t1 + ag_t2)/2;
655 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
656 else ag_t2 = ag_tx;
657 } while (ag_t1 < ag_t2);
658 (PCB).ag_ap = ag_pstt[ag_t1];
659 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
660 }
661 return (PCB).exit_flag == AG_RUNNING_CODE;
662 }
663
664 static int ag_action_6_proc(void) {
665 int ag_sd = ag_fl[(PCB).ag_ap];
666 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
667 if ((PCB).drt == -1) {
668 (PCB).drt=(PCB).token_number;
669 (PCB).dssx=(PCB).ssx;
670 (PCB).dsn=(PCB).sn;
671 }
672 if (ag_sd) {
673 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
674 }
675 else {
676 ag_prot();
677 (PCB).vs[(PCB).ssx] = ag_null_value;
678 (PCB).ss[(PCB).ssx] = (PCB).sn;
679 }
680 while ((PCB).exit_flag == AG_RUNNING_CODE) {
681 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
682 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
683 do {
684 unsigned ag_tx = (ag_t1 + ag_t2)/2;
685 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
686 else ag_t2 = ag_tx;
687 } while (ag_t1 < ag_t2);
688 (PCB).ag_ap = ag_pstt[ag_t1];
689 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
690 }
691 return (PCB).exit_flag == AG_RUNNING_CODE;
692 }
693
694
695 static int ag_action_2_er_proc(void) {
696 (PCB).btsx = 0, (PCB).drt = -1;
697 (PCB).vs[(PCB).ssx] = (PCB).input_code;
698 (PCB).ssx++;
699 (PCB).sn = (PCB).ag_ap;
700 return 0;
701 }
702
703 static int ag_action_1_er_proc(void) {
704 (PCB).btsx = 0, (PCB).drt = -1;
705 (PCB).exit_flag = AG_SUCCESS_CODE;
706 return 0;
707 }
708
709 static int ag_action_4_er_proc(void) {
710 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
711 (PCB).btsx = 0, (PCB).drt = -1;
712 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
713 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
714 else (PCB).ss[(PCB).ssx] = (PCB).sn;
715 while ((PCB).exit_flag == AG_RUNNING_CODE) {
716 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
717 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
718 do {
719 unsigned ag_tx = (ag_t1 + ag_t2)/2;
720 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
721 else ag_t2 = ag_tx;
722 } while (ag_t1 < ag_t2);
723 (PCB).ag_ap = ag_pstt[ag_t1];
724 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
725 }
726 return 0;
727 }
728
729 static int ag_action_3_er_proc(void) {
730 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
731 (PCB).btsx = 0, (PCB).drt = -1;
732 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
733 else (PCB).ss[(PCB).ssx] = (PCB).sn;
734 (PCB).reduction_token = (fc2_token_type) ag_ptt[(PCB).ag_ap];
735 ag_ra();
736 while ((PCB).exit_flag == AG_RUNNING_CODE) {
737 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
738 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
739 do {
740 unsigned ag_tx = (ag_t1 + ag_t2)/2;
741 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
742 else ag_t2 = ag_tx;
743 } while (ag_t1 < ag_t2);
744 (PCB).ag_ap = ag_pstt[ag_t1];
745 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
746 }
747 return 0;
748 }
749
750
751 void init_fc2(void) {
752 (PCB).read_flag = 1;
753 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
754 (PCB).exit_flag = AG_RUNNING_CODE;
755 (PCB).line = FIRST_LINE;
756 (PCB).column = FIRST_COLUMN;
757 (PCB).btsx = 0, (PCB).drt = -1;
758 }
759
760 void fc2(void) {
761 init_fc2();
762 (PCB).exit_flag = AG_RUNNING_CODE;
763 while ((PCB).exit_flag == AG_RUNNING_CODE) {
764 unsigned ag_t1 = ag_sbt[(PCB).sn];
765 if (ag_tstt[ag_t1]) {
766 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
767 if ((PCB).read_flag) {
768 (PCB).read_flag = 0;
769 GET_INPUT;
770 };
771 (PCB).token_number = (fc2_token_type) AG_TCV((PCB).input_code);
772 do {
773 unsigned ag_tx = (ag_t1 + ag_t2)/2;
774 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
775 ag_t1 = ag_tx + 1;
776 else ag_t2 = ag_tx;
777 } while (ag_t1 < ag_t2);
778 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number)
779 ag_t1 = ag_sbe[(PCB).sn];
780 }
781 (PCB).ag_ap = ag_pstt[ag_t1];
782 (ag_gt_procs_scan[ag_astt[ag_t1]])();
783 }
784 }
785
786
787
788 int main(void) {
789 fc2();
790 return 0;
791 }