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