Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/parsifal/good/pex1.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 PEX1_H | |
27 #include "pex1.h" | |
28 #endif | |
29 | |
30 #ifndef PEX1_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 pex1_pcb_type pex1_pcb; | |
44 #define PCB pex1_pcb | |
45 #define CHANGE_REDUCTION(x) pex1_change_reduction(pex1_##x##_token) | |
46 int pex1_change_reduction(pex1_token_type); | |
47 | |
48 | |
49 #ifndef CONVERT_CASE | |
50 | |
51 static const char agCaseTable[31] = { | |
52 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, | |
53 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, | |
54 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0, | |
55 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 | |
56 }; | |
57 | |
58 static int agConvertCase(int c) { | |
59 if (c >= 'a' && c <= 'z') return c ^= 0x20; | |
60 if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0]; | |
61 return c; | |
62 } | |
63 | |
64 #define CONVERT_CASE(c) agConvertCase(c) | |
65 | |
66 #endif | |
67 | |
68 | |
69 #ifndef TAB_SPACING | |
70 #define TAB_SPACING 8 | |
71 #endif | |
72 | |
73 #define ag_rp_1() (whileConditionPointer= PCB.pointer) | |
74 | |
75 #define ag_rp_2() (whileCompletePointer = PCB.pointer, PCB.pointer = whileConditionPointer) | |
76 | |
77 static void ag_rp_3(int x) { | |
78 /* Line -, pex1.syn */ | |
79 if (x) return; | |
80 CHANGE_REDUCTION(true_while_condition); | |
81 PCB.pointer = whileCompletePointer; | |
82 | |
83 } | |
84 | |
85 #define ag_rp_4() (PCB.pointer = whileConditionPointer) | |
86 | |
87 | |
88 #define READ_COUNTS | |
89 #define WRITE_COUNTS | |
90 #undef V | |
91 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
92 #undef VS | |
93 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
94 | |
95 #ifndef GET_CONTEXT | |
96 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
97 #endif | |
98 | |
99 typedef enum { | |
100 ag_action_1, | |
101 ag_action_2, | |
102 ag_action_3, | |
103 ag_action_4, | |
104 ag_action_5, | |
105 ag_action_6, | |
106 ag_action_7, | |
107 ag_action_8, | |
108 ag_action_9, | |
109 ag_action_10, | |
110 ag_action_11, | |
111 ag_action_12 | |
112 } ag_parser_action; | |
113 | |
114 | |
115 #ifndef NULL_VALUE_INITIALIZER | |
116 #define NULL_VALUE_INITIALIZER = 0 | |
117 #endif | |
118 | |
119 static int const ag_null_value NULL_VALUE_INITIALIZER; | |
120 | |
121 static const unsigned char ag_rpx[] = { | |
122 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, | |
123 0, 4 | |
124 }; | |
125 | |
126 static const unsigned char ag_key_itt[] = { | |
127 0 | |
128 }; | |
129 | |
130 static const unsigned short ag_key_pt[] = { | |
131 0 | |
132 }; | |
133 | |
134 static const unsigned char ag_key_ch[] = { | |
135 0, 33,255 | |
136 }; | |
137 | |
138 static const unsigned char ag_key_act[] = { | |
139 0,3,4 | |
140 }; | |
141 | |
142 static const unsigned char ag_key_parm[] = { | |
143 0, 26, 0 | |
144 }; | |
145 | |
146 static const unsigned char ag_key_jmp[] = { | |
147 0, 0, 0 | |
148 }; | |
149 | |
150 static const unsigned char ag_key_index[] = { | |
151 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
152 }; | |
153 | |
154 static const unsigned char ag_key_ends[] = { | |
155 87,72,73,76,69,0, | |
156 }; | |
157 #define AG_TCV(x) (((int)(x) >= 0 && (int)(x) <= 255) ? ag_tcv[(x)] : 0) | |
158 | |
159 static const unsigned char ag_tcv[] = { | |
160 29, 29, 29, 29, 29, 29, 29, 29, 29, 33, 29, 29, 29, 29, 29, 29, 29, 29, | |
161 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 33, 29, 29, 29, | |
162 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
163 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
164 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
165 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
166 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
167 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
168 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
169 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
170 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
171 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
172 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
173 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, | |
174 29, 29, 29, 29 | |
175 }; | |
176 | |
177 #ifndef SYNTAX_ERROR | |
178 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
179 (PCB).error_message, (PCB).line, (PCB).column) | |
180 #endif | |
181 | |
182 #ifndef FIRST_LINE | |
183 #define FIRST_LINE 1 | |
184 #endif | |
185 | |
186 #ifndef FIRST_COLUMN | |
187 #define FIRST_COLUMN 1 | |
188 #endif | |
189 | |
190 #ifndef PARSER_STACK_OVERFLOW | |
191 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
192 "\nParser stack overflow, line %d, column %d\n",\ | |
193 (PCB).line, (PCB).column);} | |
194 #endif | |
195 | |
196 #ifndef REDUCTION_TOKEN_ERROR | |
197 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
198 "\nReduction token error, line %d, column %d\n", \ | |
199 (PCB).line, (PCB).column);} | |
200 #endif | |
201 | |
202 | |
203 typedef enum | |
204 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
205 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
206 | |
207 #ifndef GET_INPUT | |
208 #define GET_INPUT ((PCB).input_code = getchar()) | |
209 #endif | |
210 | |
211 | |
212 static int ag_look_ahead(void) { | |
213 if ((PCB).rx < (PCB).fx) { | |
214 return CONVERT_CASE((PCB).lab[(PCB).rx++]); | |
215 } | |
216 GET_INPUT; | |
217 (PCB).fx++; | |
218 return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code); | |
219 } | |
220 | |
221 static void ag_get_key_word(int ag_k) { | |
222 int save_index = (PCB).rx; | |
223 const unsigned char *sp; | |
224 int ag_ch; | |
225 while (1) { | |
226 switch (ag_key_act[ag_k]) { | |
227 case ag_cf_end_key: | |
228 sp = ag_key_ends + ag_key_jmp[ag_k]; | |
229 do { | |
230 if ((ag_ch = *sp++) == 0) { | |
231 int ag_k1 = ag_key_parm[ag_k]; | |
232 int ag_k2 = ag_key_pt[ag_k1]; | |
233 if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail; | |
234 (PCB).rx--; | |
235 (PCB).token_number = (pex1_token_type) ag_key_pt[ag_k1 + 1]; | |
236 return; | |
237 } | |
238 } while (ag_look_ahead() == ag_ch); | |
239 goto ag_fail; | |
240 case ag_end_key: | |
241 sp = ag_key_ends + ag_key_jmp[ag_k]; | |
242 do { | |
243 if ((ag_ch = *sp++) == 0) { | |
244 (PCB).token_number = (pex1_token_type) ag_key_parm[ag_k]; | |
245 return; | |
246 } | |
247 } while (ag_look_ahead() == ag_ch); | |
248 case ag_no_match_key: | |
249 ag_fail: | |
250 (PCB).rx = save_index; | |
251 return; | |
252 case ag_cf_set_key: { | |
253 int ag_k1 = ag_key_parm[ag_k]; | |
254 int ag_k2 = ag_key_pt[ag_k1]; | |
255 ag_k = ag_key_jmp[ag_k]; | |
256 if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break; | |
257 save_index = --(PCB).rx; | |
258 (PCB).token_number = (pex1_token_type) ag_key_pt[ag_k1+1]; | |
259 break; | |
260 } | |
261 case ag_set_key: | |
262 save_index = (PCB).rx; | |
263 (PCB).token_number = (pex1_token_type) ag_key_parm[ag_k]; | |
264 case ag_jmp_key: | |
265 ag_k = ag_key_jmp[ag_k]; | |
266 ag_ch = ag_look_ahead(); | |
267 break; | |
268 case ag_accept_key: | |
269 (PCB).token_number = (pex1_token_type) ag_key_parm[ag_k]; | |
270 return; | |
271 case ag_cf_accept_key: { | |
272 int ag_k1 = ag_key_parm[ag_k]; | |
273 int ag_k2 = ag_key_pt[ag_k1]; | |
274 if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index; | |
275 else { | |
276 (PCB).rx--; | |
277 (PCB).token_number = (pex1_token_type) ag_key_pt[ag_k1+1]; | |
278 } | |
279 return; | |
280 } | |
281 default: | |
282 /* not reachable; here to suppress compiler warnings */ | |
283 goto ag_fail; | |
284 } | |
285 if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
286 if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) { | |
287 (PCB).rx = save_index; | |
288 return; | |
289 } | |
290 } | |
291 } | |
292 | |
293 | |
294 #ifndef AG_NEWLINE | |
295 #define AG_NEWLINE 10 | |
296 #endif | |
297 | |
298 #ifndef AG_RETURN | |
299 #define AG_RETURN 13 | |
300 #endif | |
301 | |
302 #ifndef AG_FORMFEED | |
303 #define AG_FORMFEED 12 | |
304 #endif | |
305 | |
306 #ifndef AG_TABCHAR | |
307 #define AG_TABCHAR 9 | |
308 #endif | |
309 | |
310 static void ag_track(void) { | |
311 int ag_k = 0; | |
312 while (ag_k < (PCB).rx) { | |
313 int ag_ch = (PCB).lab[ag_k++]; | |
314 switch (ag_ch) { | |
315 case AG_NEWLINE: | |
316 (PCB).column = 1, (PCB).line++; | |
317 case AG_RETURN: | |
318 case AG_FORMFEED: | |
319 break; | |
320 case AG_TABCHAR: | |
321 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
322 break; | |
323 default: | |
324 (PCB).column++; | |
325 } | |
326 } | |
327 ag_k = 0; | |
328 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++]; | |
329 (PCB).fx = ag_k; | |
330 (PCB).rx = 0; | |
331 } | |
332 | |
333 | |
334 static void ag_prot(void) { | |
335 int ag_k; | |
336 ag_k = 128 - ++(PCB).btsx; | |
337 if (ag_k <= (PCB).ssx) { | |
338 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
339 PARSER_STACK_OVERFLOW; | |
340 return; | |
341 } | |
342 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
343 (PCB).bts[ag_k] = (PCB).ssx; | |
344 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
345 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
346 } | |
347 | |
348 static void ag_undo(void) { | |
349 if ((PCB).drt == -1) return; | |
350 while ((PCB).btsx) { | |
351 int ag_k = 128 - (PCB).btsx; | |
352 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
353 (PCB).ssx = (PCB).bts[ag_k]; | |
354 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
355 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
356 } | |
357 (PCB).token_number = (pex1_token_type) (PCB).drt; | |
358 (PCB).ssx = (PCB).dssx; | |
359 (PCB).sn = (PCB).dsn; | |
360 (PCB).drt = -1; | |
361 } | |
362 | |
363 | |
364 | |
365 static const int ag_rtt[] = { | |
366 16, 17, 0 | |
367 }; | |
368 | |
369 static const unsigned char ag_tstt[] = { | |
370 33,26,3,0,1,24,25, | |
371 33,3,0,1, | |
372 26,0,4,5,19, | |
373 33,30,29,3,0,1,24,25, | |
374 30,29,0,9,10,14, | |
375 33,30,29,3,0,1,24,25, | |
376 33,30,29,0,2,10,12,13, | |
377 30,0,15, | |
378 31,0,16,18,20,21,22, | |
379 33,30,29,3,0,1,24,25, | |
380 33,29,0,2,10, | |
381 33,31,3,0,1,24,25, | |
382 33,32,3,0,1,24,25, | |
383 32,0,23, | |
384 31,0,16,18,20, | |
385 31,0,17,18, | |
386 33,30,3,0,1,24,25, | |
387 30,0,15, | |
388 | |
389 }; | |
390 | |
391 | |
392 static unsigned const char ag_astt[105] = { | |
393 1,8,1,7,1,1,1,9,9,5,3,1,7,1,2,0,1,5,5,1,7,1,1,3,8,1,7,1,1,1,1,5,5,1,7,1,1, | |
394 3,1,5,1,7,1,1,1,3,1,7,2,1,7,1,2,1,1,1,1,5,5,1,7,1,1,3,1,1,5,3,3,1,5,1,7,1, | |
395 1,3,1,5,1,7,1,1,3,1,7,1,1,5,1,2,3,1,7,3,2,1,5,1,7,1,1,3,1,7,2 | |
396 }; | |
397 | |
398 | |
399 static const unsigned char ag_pstt[] = { | |
400 1,2,1,0,1,1,2, | |
401 23,23,25,23, | |
402 3,2,4,3,0, | |
403 1,24,24,1,3,1,1,26, | |
404 7,5,4,8,6,7, | |
405 1,24,24,1,5,1,1,29, | |
406 9,8,5,6,10,10,10,11, | |
407 11,7,12, | |
408 12,8,13,13,14,14,15, | |
409 1,24,24,1,9,1,1,33, | |
410 9,5,9,7,7, | |
411 1,24,1,11,1,1,30, | |
412 1,24,1,12,1,1,31, | |
413 16,13,17, | |
414 12,17,13,13,15, | |
415 12,15,18,13, | |
416 1,24,1,16,1,1,32, | |
417 11,17,19, | |
418 | |
419 }; | |
420 | |
421 | |
422 static const unsigned char ag_sbt[] = { | |
423 0, 7, 11, 16, 24, 30, 38, 46, 49, 56, 64, 69, 76, 83, | |
424 86, 91, 95, 102, 105 | |
425 }; | |
426 | |
427 | |
428 static const unsigned char ag_sbe[] = { | |
429 3, 9, 12, 20, 26, 34, 41, 47, 50, 60, 66, 72, 79, 84, | |
430 87, 92, 98, 103, 105 | |
431 }; | |
432 | |
433 | |
434 static const unsigned char ag_fl[] = { | |
435 2,1,1,1,1,1,1,2,0,1,0,2,2,1,1,2,0,1,4,3,1,1,1,2,0,1,2,2,2,2,2,2,2,2 | |
436 }; | |
437 | |
438 static const unsigned char ag_ptt[] = { | |
439 0, 1, 1, 4, 6, 6, 12, 12, 13, 13, 14, 14, 9, 16, 21, 21, 22, 22, | |
440 19, 20, 11, 11, 24, 24, 25, 25, 5, 7, 8, 10, 15, 18, 23, 2 | |
441 }; | |
442 | |
443 static const unsigned char *ag_valid(int ag_k) { | |
444 const unsigned char *ag_tp = &ag_tstt[ag_sbt[(PCB).sn+1]]; | |
445 while (*--ag_tp != (unsigned char) ag_k) if (*ag_tp == 0) return NULL; | |
446 return ag_tp; | |
447 } | |
448 | |
449 int pex1_change_reduction(pex1_token_type ag_k) { | |
450 if (!ag_valid(ag_k)) return 0; | |
451 (PCB).reduction_token = ag_k; | |
452 return 1; | |
453 } | |
454 | |
455 static void ag_default(const int *ag_tp) { | |
456 (PCB).ag_dsn = (PCB).sn; | |
457 (PCB).ag_dtl = ag_tp; | |
458 while (!ag_valid((pex1_token_type) *ag_tp)) ag_tp++; | |
459 (PCB).reduction_token = (pex1_token_type) *ag_tp; | |
460 } | |
461 | |
462 | |
463 | |
464 static void ag_ra(void) | |
465 { | |
466 switch(ag_rpx[(PCB).ag_ap]) { | |
467 case 1: ag_rp_1(); break; | |
468 case 2: ag_rp_2(); break; | |
469 case 3: ag_default(&ag_rtt[0]); ag_rp_3(VS(0)); break; | |
470 case 4: ag_rp_4(); break; | |
471 } | |
472 } | |
473 | |
474 #define TOKEN_NAMES pex1_token_names | |
475 const char *const pex1_token_names[34] = { | |
476 "while loop", | |
477 "white space", | |
478 "space", | |
479 "comment", | |
480 "while head", | |
481 "\"!WHILE\"", | |
482 "while terminator", | |
483 "\"!ENDW\"", | |
484 "\"!ENDWHILE\"", | |
485 "while body text", | |
486 "", | |
487 "", | |
488 "", | |
489 "", | |
490 "", | |
491 "while body terminator", | |
492 "true while condition", | |
493 "false while condition", | |
494 "expression", | |
495 "while loop", | |
496 "while iteration", | |
497 "", | |
498 "", | |
499 "while body", | |
500 "", | |
501 "", | |
502 "\"!WHILE\"", | |
503 "\"!ENDW\"", | |
504 "\"!ENDWHILE\"", | |
505 "", | |
506 "while body terminator", | |
507 "expression", | |
508 "while body", | |
509 "space", | |
510 | |
511 }; | |
512 | |
513 #ifndef MISSING_FORMAT | |
514 #define MISSING_FORMAT "Missing %s" | |
515 #endif | |
516 #ifndef UNEXPECTED_FORMAT | |
517 #define UNEXPECTED_FORMAT "Unexpected %s" | |
518 #endif | |
519 #ifndef UNNAMED_TOKEN | |
520 #define UNNAMED_TOKEN "input" | |
521 #endif | |
522 | |
523 | |
524 static void ag_diagnose(void) { | |
525 int ag_snd = (PCB).sn; | |
526 int ag_k = ag_sbt[ag_snd]; | |
527 | |
528 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
529 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
530 } | |
531 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
532 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
533 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
534 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
535 } | |
536 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
537 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
538 } | |
539 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') { | |
540 char buf[20]; | |
541 sprintf(buf, "\'%c\'", (char) (*(PCB).lab)); | |
542 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
543 } | |
544 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
545 (PCB).error_message = (PCB).ag_msg; | |
546 | |
547 | |
548 } | |
549 static int ag_action_1_r_proc(void); | |
550 static int ag_action_2_r_proc(void); | |
551 static int ag_action_3_r_proc(void); | |
552 static int ag_action_4_r_proc(void); | |
553 static int ag_action_1_s_proc(void); | |
554 static int ag_action_3_s_proc(void); | |
555 static int ag_action_1_proc(void); | |
556 static int ag_action_2_proc(void); | |
557 static int ag_action_3_proc(void); | |
558 static int ag_action_4_proc(void); | |
559 static int ag_action_5_proc(void); | |
560 static int ag_action_6_proc(void); | |
561 static int ag_action_7_proc(void); | |
562 static int ag_action_8_proc(void); | |
563 static int ag_action_9_proc(void); | |
564 static int ag_action_10_proc(void); | |
565 static int ag_action_11_proc(void); | |
566 static int ag_action_8_proc(void); | |
567 | |
568 | |
569 static int (*const ag_r_procs_scan[])(void) = { | |
570 ag_action_1_r_proc, | |
571 ag_action_2_r_proc, | |
572 ag_action_3_r_proc, | |
573 ag_action_4_r_proc | |
574 }; | |
575 | |
576 static int (*const ag_s_procs_scan[])(void) = { | |
577 ag_action_1_s_proc, | |
578 ag_action_2_r_proc, | |
579 ag_action_3_s_proc, | |
580 ag_action_4_r_proc | |
581 }; | |
582 | |
583 static int (*const ag_gt_procs_scan[])(void) = { | |
584 ag_action_1_proc, | |
585 ag_action_2_proc, | |
586 ag_action_3_proc, | |
587 ag_action_4_proc, | |
588 ag_action_5_proc, | |
589 ag_action_6_proc, | |
590 ag_action_7_proc, | |
591 ag_action_8_proc, | |
592 ag_action_9_proc, | |
593 ag_action_10_proc, | |
594 ag_action_11_proc, | |
595 ag_action_8_proc | |
596 }; | |
597 | |
598 | |
599 static int ag_action_10_proc(void) { | |
600 int ag_t = (PCB).token_number; | |
601 (PCB).btsx = 0, (PCB).drt = -1; | |
602 do { | |
603 ag_track(); | |
604 if ((PCB).rx < (PCB).fx) { | |
605 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
606 (PCB).token_number = (pex1_token_type) AG_TCV((PCB).input_code);} | |
607 else { | |
608 GET_INPUT; | |
609 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
610 (PCB).token_number = (pex1_token_type) AG_TCV((PCB).input_code); | |
611 (PCB).rx++; | |
612 } | |
613 if (ag_key_index[(PCB).sn]) { | |
614 unsigned ag_k = ag_key_index[(PCB).sn]; | |
615 int ag_ch = CONVERT_CASE((PCB).input_code); | |
616 if (ag_ch < 255) { | |
617 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
618 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
619 } | |
620 } | |
621 } while ((PCB).token_number == (pex1_token_type) ag_t); | |
622 (PCB).rx = 0; | |
623 return 1; | |
624 } | |
625 | |
626 static int ag_action_11_proc(void) { | |
627 int ag_t = (PCB).token_number; | |
628 | |
629 (PCB).btsx = 0, (PCB).drt = -1; | |
630 do { | |
631 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
632 (PCB).ssx--; | |
633 ag_track(); | |
634 ag_ra(); | |
635 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
636 (PCB).ssx++; | |
637 if ((PCB).rx < (PCB).fx) { | |
638 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
639 (PCB).token_number = (pex1_token_type) AG_TCV((PCB).input_code);} | |
640 else { | |
641 GET_INPUT; | |
642 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
643 (PCB).token_number = (pex1_token_type) AG_TCV((PCB).input_code); | |
644 (PCB).rx++; | |
645 } | |
646 if (ag_key_index[(PCB).sn]) { | |
647 unsigned ag_k = ag_key_index[(PCB).sn]; | |
648 int ag_ch = CONVERT_CASE((PCB).input_code); | |
649 if (ag_ch < 255) { | |
650 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
651 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
652 } | |
653 } | |
654 } | |
655 while ((PCB).token_number == (pex1_token_type) ag_t); | |
656 (PCB).rx = 0; | |
657 return 1; | |
658 } | |
659 | |
660 static int ag_action_3_r_proc(void) { | |
661 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
662 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
663 (PCB).btsx = 0, (PCB).drt = -1; | |
664 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
665 ag_ra(); | |
666 return (PCB).exit_flag == AG_RUNNING_CODE; | |
667 } | |
668 | |
669 static int ag_action_3_s_proc(void) { | |
670 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
671 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
672 (PCB).btsx = 0, (PCB).drt = -1; | |
673 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
674 ag_ra(); | |
675 return (PCB).exit_flag == AG_RUNNING_CODE; | |
676 } | |
677 | |
678 static int ag_action_4_r_proc(void) { | |
679 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
680 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
681 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
682 return 1; | |
683 } | |
684 | |
685 static int ag_action_2_proc(void) { | |
686 (PCB).btsx = 0, (PCB).drt = -1; | |
687 if ((PCB).ssx >= 128) { | |
688 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
689 PARSER_STACK_OVERFLOW; | |
690 } | |
691 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
692 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
693 (PCB).ssx++; | |
694 (PCB).sn = (PCB).ag_ap; | |
695 ag_track(); | |
696 return 0; | |
697 } | |
698 | |
699 static int ag_action_9_proc(void) { | |
700 if ((PCB).drt == -1) { | |
701 (PCB).drt=(PCB).token_number; | |
702 (PCB).dssx=(PCB).ssx; | |
703 (PCB).dsn=(PCB).sn; | |
704 } | |
705 ag_prot(); | |
706 (PCB).vs[(PCB).ssx] = ag_null_value; | |
707 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
708 (PCB).ssx++; | |
709 (PCB).sn = (PCB).ag_ap; | |
710 (PCB).rx = 0; | |
711 return (PCB).exit_flag == AG_RUNNING_CODE; | |
712 } | |
713 | |
714 static int ag_action_2_r_proc(void) { | |
715 (PCB).ssx++; | |
716 (PCB).sn = (PCB).ag_ap; | |
717 return 0; | |
718 } | |
719 | |
720 static int ag_action_7_proc(void) { | |
721 --(PCB).ssx; | |
722 (PCB).rx = 0; | |
723 (PCB).exit_flag = AG_SUCCESS_CODE; | |
724 return 0; | |
725 } | |
726 | |
727 static int ag_action_1_proc(void) { | |
728 ag_track(); | |
729 (PCB).exit_flag = AG_SUCCESS_CODE; | |
730 return 0; | |
731 } | |
732 | |
733 static int ag_action_1_r_proc(void) { | |
734 (PCB).exit_flag = AG_SUCCESS_CODE; | |
735 return 0; | |
736 } | |
737 | |
738 static int ag_action_1_s_proc(void) { | |
739 (PCB).exit_flag = AG_SUCCESS_CODE; | |
740 return 0; | |
741 } | |
742 | |
743 static int ag_action_4_proc(void) { | |
744 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
745 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
746 (PCB).btsx = 0, (PCB).drt = -1; | |
747 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
748 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
749 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
750 ag_track(); | |
751 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
752 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
753 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
754 do { | |
755 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
756 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
757 else ag_t2 = ag_tx; | |
758 } while (ag_t1 < ag_t2); | |
759 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
760 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
761 REDUCTION_TOKEN_ERROR; break;} | |
762 (PCB).ag_ap = ag_pstt[ag_t1]; | |
763 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
764 } | |
765 return 0; | |
766 } | |
767 | |
768 static int ag_action_3_proc(void) { | |
769 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
770 (PCB).btsx = 0, (PCB).drt = -1; | |
771 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
772 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
773 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
774 ag_track(); | |
775 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
776 ag_ra(); | |
777 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
778 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
779 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
780 do { | |
781 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
782 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
783 else ag_t2 = ag_tx; | |
784 } while (ag_t1 < ag_t2); | |
785 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
786 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
787 REDUCTION_TOKEN_ERROR; break;} | |
788 (PCB).ag_ap = ag_pstt[ag_t1]; | |
789 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
790 } | |
791 return 0; | |
792 } | |
793 | |
794 static int ag_action_8_proc(void) { | |
795 ag_undo(); | |
796 (PCB).rx = 0; | |
797 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
798 ag_diagnose(); | |
799 SYNTAX_ERROR; | |
800 {(PCB).rx = 1; ag_track();} | |
801 return (PCB).exit_flag == AG_RUNNING_CODE; | |
802 } | |
803 | |
804 static int ag_action_5_proc(void) { | |
805 int ag_sd = ag_fl[(PCB).ag_ap]; | |
806 (PCB).btsx = 0, (PCB).drt = -1; | |
807 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
808 else { | |
809 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
810 } | |
811 (PCB).rx = 0; | |
812 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
813 ag_ra(); | |
814 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
815 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
816 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
817 do { | |
818 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
819 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
820 else ag_t2 = ag_tx; | |
821 } while (ag_t1 < ag_t2); | |
822 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
823 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
824 REDUCTION_TOKEN_ERROR; break;} | |
825 (PCB).ag_ap = ag_pstt[ag_t1]; | |
826 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
827 } | |
828 return (PCB).exit_flag == AG_RUNNING_CODE; | |
829 } | |
830 | |
831 static int ag_action_6_proc(void) { | |
832 int ag_sd = ag_fl[(PCB).ag_ap]; | |
833 (PCB).reduction_token = (pex1_token_type) ag_ptt[(PCB).ag_ap]; | |
834 if ((PCB).drt == -1) { | |
835 (PCB).drt=(PCB).token_number; | |
836 (PCB).dssx=(PCB).ssx; | |
837 (PCB).dsn=(PCB).sn; | |
838 } | |
839 if (ag_sd) { | |
840 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
841 } | |
842 else { | |
843 ag_prot(); | |
844 (PCB).vs[(PCB).ssx] = ag_null_value; | |
845 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
846 } | |
847 (PCB).rx = 0; | |
848 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
849 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
850 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
851 do { | |
852 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
853 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
854 else ag_t2 = ag_tx; | |
855 } while (ag_t1 < ag_t2); | |
856 if (ag_tstt[ag_t1] != (PCB).reduction_token) { | |
857 (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; | |
858 REDUCTION_TOKEN_ERROR; break;} | |
859 (PCB).ag_ap = ag_pstt[ag_t1]; | |
860 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
861 } | |
862 return (PCB).exit_flag == AG_RUNNING_CODE; | |
863 } | |
864 | |
865 | |
866 void init_pex1(void) { | |
867 (PCB).rx = (PCB).fx = 0; | |
868 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
869 (PCB).exit_flag = AG_RUNNING_CODE; | |
870 (PCB).line = FIRST_LINE; | |
871 (PCB).column = FIRST_COLUMN; | |
872 (PCB).btsx = 0, (PCB).drt = -1; | |
873 } | |
874 | |
875 void pex1(void) { | |
876 init_pex1(); | |
877 (PCB).exit_flag = AG_RUNNING_CODE; | |
878 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
879 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
880 if (ag_tstt[ag_t1]) { | |
881 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
882 if ((PCB).rx < (PCB).fx) { | |
883 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
884 (PCB).token_number = (pex1_token_type) AG_TCV((PCB).input_code);} | |
885 else { | |
886 GET_INPUT; | |
887 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
888 (PCB).token_number = (pex1_token_type) AG_TCV((PCB).input_code); | |
889 (PCB).rx++; | |
890 } | |
891 if (ag_key_index[(PCB).sn]) { | |
892 unsigned ag_k = ag_key_index[(PCB).sn]; | |
893 int ag_ch = CONVERT_CASE((PCB).input_code); | |
894 if (ag_ch < 255) { | |
895 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
896 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
897 } | |
898 } | |
899 do { | |
900 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
901 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
902 ag_t1 = ag_tx + 1; | |
903 else ag_t2 = ag_tx; | |
904 } while (ag_t1 < ag_t2); | |
905 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
906 ag_t1 = ag_sbe[(PCB).sn]; | |
907 } | |
908 (PCB).ag_ap = ag_pstt[ag_t1]; | |
909 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
910 } | |
911 } | |
912 | |
913 | |
914 | |
915 int main(void) { | |
916 pex1(); | |
917 return 0; | |
918 } |