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