Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/parsifal/good/test1.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 TEST1_H | |
28 #include "test1.h" | |
29 #endif | |
30 | |
31 #ifndef TEST1_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 test1_pcb_type test1_pcb; | |
45 #define PCB test1_pcb | |
46 | |
47 /* Line -, test1.syn */ | |
48 int main(void) { | |
49 /* | |
50 int c; | |
51 init_test2(); | |
52 do { | |
53 c = getchar(); | |
54 PCB.input_code = c; | |
55 test2(); | |
56 } while ( c != '\n'); | |
57 */ | |
58 test1(); | |
59 return 0; | |
60 } | |
61 | |
62 #ifndef CONVERT_CASE | |
63 #define CONVERT_CASE(c) (c) | |
64 #endif | |
65 #ifndef TAB_SPACING | |
66 #define TAB_SPACING 8 | |
67 #endif | |
68 | |
69 #define ag_rp_1() (printf("if\n")) | |
70 | |
71 #define ag_rp_2() (printf("ifx\n")) | |
72 | |
73 #define ag_rp_3(c) (printf("%c", c)) | |
74 | |
75 #define ag_rp_4(c) (printf("%c", c)) | |
76 | |
77 | |
78 #define READ_COUNTS | |
79 #define WRITE_COUNTS | |
80 #undef V | |
81 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
82 #undef VS | |
83 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
84 | |
85 #ifndef GET_CONTEXT | |
86 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
87 #endif | |
88 | |
89 typedef enum { | |
90 ag_action_1, | |
91 ag_action_2, | |
92 ag_action_3, | |
93 ag_action_4, | |
94 ag_action_5, | |
95 ag_action_6, | |
96 ag_action_7, | |
97 ag_action_8, | |
98 ag_action_9, | |
99 ag_action_10, | |
100 ag_action_11, | |
101 ag_action_12 | |
102 } ag_parser_action; | |
103 | |
104 | |
105 #ifndef NULL_VALUE_INITIALIZER | |
106 #define NULL_VALUE_INITIALIZER = 0 | |
107 #endif | |
108 | |
109 static int const ag_null_value NULL_VALUE_INITIALIZER; | |
110 | |
111 static const unsigned char ag_rpx[] = { | |
112 0, 0, 0, 0, 0, 1, 2, 0, 3, 4 | |
113 }; | |
114 | |
115 static const unsigned char ag_key_itt[] = { | |
116 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
118 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, | |
119 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, | |
120 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
121 1, 1, 1, 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, 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, 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, 0, 0, 0, 0, 0, 0, | |
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
127 0 | |
128 }; | |
129 | |
130 static const unsigned short ag_key_pt[] = { | |
131 0, 2, 0, 8,0 | |
132 }; | |
133 | |
134 static const unsigned char ag_key_ch[] = { | |
135 0,120,255,102,255,105,255 | |
136 }; | |
137 | |
138 static const unsigned char ag_key_act[] = { | |
139 0,5,4,6,4,2,4 | |
140 }; | |
141 | |
142 static const unsigned char ag_key_parm[] = { | |
143 0, 2, 0, 0, 0, 0, 0 | |
144 }; | |
145 | |
146 static const unsigned char ag_key_jmp[] = { | |
147 0, 0, 0, 1, 0, 3, 0 | |
148 }; | |
149 | |
150 static const unsigned char ag_key_index[] = { | |
151 5, 0, 0, 0, 0, 0, 0, 0, 0 | |
152 }; | |
153 | |
154 static const unsigned char ag_key_ends[] = { | |
155 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 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 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, 3, 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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
172 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
173 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | |
174 4, 4, 4, 4 | |
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 = (test1_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 = (test1_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 = (test1_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 = (test1_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 = (test1_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 = (test1_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 = (test1_token_type) (PCB).drt; | |
358 (PCB).ssx = (PCB).dssx; | |
359 (PCB).sn = (PCB).dsn; | |
360 (PCB).drt = -1; | |
361 } | |
362 | |
363 | |
364 static const unsigned char ag_tstt[] = { | |
365 8,4,3,2,0,1,9, | |
366 7,4,3,0, | |
367 3,0, | |
368 3,0, | |
369 7,4,0,5,6, | |
370 7,4,0,5,6, | |
371 4,0, | |
372 7,0, | |
373 7,0, | |
374 | |
375 }; | |
376 | |
377 | |
378 static unsigned const char ag_astt[31] = { | |
379 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 | |
380 }; | |
381 | |
382 | |
383 static const unsigned char ag_pstt[] = { | |
384 2,8,8,3,0,0,1, | |
385 7,9,9,1, | |
386 4,2, | |
387 5,3, | |
388 7,6,4,6,7, | |
389 8,6,5,6,8, | |
390 2,4, | |
391 6,7, | |
392 5,8, | |
393 | |
394 }; | |
395 | |
396 | |
397 static const unsigned char ag_sbt[] = { | |
398 0, 7, 11, 13, 15, 20, 25, 27, 29, 31 | |
399 }; | |
400 | |
401 | |
402 static const unsigned char ag_sbe[] = { | |
403 4, 10, 12, 14, 17, 22, 26, 28, 30, 31 | |
404 }; | |
405 | |
406 | |
407 static const unsigned char ag_fl[] = { | |
408 1,1,2,0,1,4,4,2,1,2 | |
409 }; | |
410 | |
411 static const unsigned char ag_ptt[] = { | |
412 0, 5, 5, 6, 6, 1, 1, 1, 9, 9 | |
413 }; | |
414 | |
415 | |
416 static void ag_ra(void) | |
417 { | |
418 switch(ag_rpx[(PCB).ag_ap]) { | |
419 case 1: ag_rp_1(); break; | |
420 case 2: ag_rp_2(); break; | |
421 case 3: ag_rp_3(VS(0)); break; | |
422 case 4: ag_rp_4(VS(1)); break; | |
423 } | |
424 } | |
425 | |
426 #define TOKEN_NAMES test1_token_names | |
427 const char *const test1_token_names[11] = { | |
428 "line", | |
429 "line", | |
430 "\"if\"", | |
431 "'('", | |
432 "", | |
433 "", | |
434 "", | |
435 "eol", | |
436 "\"ifx\"", | |
437 "other stuff", | |
438 "", | |
439 | |
440 }; | |
441 | |
442 #ifndef MISSING_FORMAT | |
443 #define MISSING_FORMAT "Missing %s" | |
444 #endif | |
445 #ifndef UNEXPECTED_FORMAT | |
446 #define UNEXPECTED_FORMAT "Unexpected %s" | |
447 #endif | |
448 #ifndef UNNAMED_TOKEN | |
449 #define UNNAMED_TOKEN "input" | |
450 #endif | |
451 | |
452 | |
453 static void ag_diagnose(void) { | |
454 int ag_snd = (PCB).sn; | |
455 int ag_k = ag_sbt[ag_snd]; | |
456 | |
457 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
458 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
459 } | |
460 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
461 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
462 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
463 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
464 } | |
465 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
466 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
467 } | |
468 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') { | |
469 char buf[20]; | |
470 sprintf(buf, "\'%c\'", (char) (*(PCB).lab)); | |
471 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
472 } | |
473 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
474 (PCB).error_message = (PCB).ag_msg; | |
475 | |
476 | |
477 } | |
478 static int ag_action_1_r_proc(void); | |
479 static int ag_action_2_r_proc(void); | |
480 static int ag_action_3_r_proc(void); | |
481 static int ag_action_4_r_proc(void); | |
482 static int ag_action_1_s_proc(void); | |
483 static int ag_action_3_s_proc(void); | |
484 static int ag_action_1_proc(void); | |
485 static int ag_action_2_proc(void); | |
486 static int ag_action_3_proc(void); | |
487 static int ag_action_4_proc(void); | |
488 static int ag_action_5_proc(void); | |
489 static int ag_action_6_proc(void); | |
490 static int ag_action_7_proc(void); | |
491 static int ag_action_8_proc(void); | |
492 static int ag_action_9_proc(void); | |
493 static int ag_action_10_proc(void); | |
494 static int ag_action_11_proc(void); | |
495 static int ag_action_8_proc(void); | |
496 | |
497 | |
498 static int (*const ag_r_procs_scan[])(void) = { | |
499 ag_action_1_r_proc, | |
500 ag_action_2_r_proc, | |
501 ag_action_3_r_proc, | |
502 ag_action_4_r_proc | |
503 }; | |
504 | |
505 static int (*const ag_s_procs_scan[])(void) = { | |
506 ag_action_1_s_proc, | |
507 ag_action_2_r_proc, | |
508 ag_action_3_s_proc, | |
509 ag_action_4_r_proc | |
510 }; | |
511 | |
512 static int (*const ag_gt_procs_scan[])(void) = { | |
513 ag_action_1_proc, | |
514 ag_action_2_proc, | |
515 ag_action_3_proc, | |
516 ag_action_4_proc, | |
517 ag_action_5_proc, | |
518 ag_action_6_proc, | |
519 ag_action_7_proc, | |
520 ag_action_8_proc, | |
521 ag_action_9_proc, | |
522 ag_action_10_proc, | |
523 ag_action_11_proc, | |
524 ag_action_8_proc | |
525 }; | |
526 | |
527 | |
528 static int ag_action_10_proc(void) { | |
529 int ag_t = (PCB).token_number; | |
530 (PCB).btsx = 0, (PCB).drt = -1; | |
531 do { | |
532 ag_track(); | |
533 if ((PCB).rx < (PCB).fx) { | |
534 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
535 (PCB).token_number = (test1_token_type) AG_TCV((PCB).input_code);} | |
536 else { | |
537 GET_INPUT; | |
538 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
539 (PCB).token_number = (test1_token_type) AG_TCV((PCB).input_code); | |
540 (PCB).rx++; | |
541 } | |
542 if (ag_key_index[(PCB).sn]) { | |
543 unsigned ag_k = ag_key_index[(PCB).sn]; | |
544 int ag_ch = CONVERT_CASE((PCB).input_code); | |
545 if (ag_ch < 255) { | |
546 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
547 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
548 } | |
549 } | |
550 } while ((PCB).token_number == (test1_token_type) ag_t); | |
551 (PCB).rx = 0; | |
552 return 1; | |
553 } | |
554 | |
555 static int ag_action_11_proc(void) { | |
556 int ag_t = (PCB).token_number; | |
557 | |
558 (PCB).btsx = 0, (PCB).drt = -1; | |
559 do { | |
560 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
561 (PCB).ssx--; | |
562 ag_track(); | |
563 ag_ra(); | |
564 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
565 (PCB).ssx++; | |
566 if ((PCB).rx < (PCB).fx) { | |
567 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
568 (PCB).token_number = (test1_token_type) AG_TCV((PCB).input_code);} | |
569 else { | |
570 GET_INPUT; | |
571 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
572 (PCB).token_number = (test1_token_type) AG_TCV((PCB).input_code); | |
573 (PCB).rx++; | |
574 } | |
575 if (ag_key_index[(PCB).sn]) { | |
576 unsigned ag_k = ag_key_index[(PCB).sn]; | |
577 int ag_ch = CONVERT_CASE((PCB).input_code); | |
578 if (ag_ch < 255) { | |
579 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
580 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
581 } | |
582 } | |
583 } | |
584 while ((PCB).token_number == (test1_token_type) ag_t); | |
585 (PCB).rx = 0; | |
586 return 1; | |
587 } | |
588 | |
589 static int ag_action_3_r_proc(void) { | |
590 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
591 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
592 (PCB).btsx = 0, (PCB).drt = -1; | |
593 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
594 ag_ra(); | |
595 return (PCB).exit_flag == AG_RUNNING_CODE; | |
596 } | |
597 | |
598 static int ag_action_3_s_proc(void) { | |
599 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
600 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
601 (PCB).btsx = 0, (PCB).drt = -1; | |
602 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
603 ag_ra(); | |
604 return (PCB).exit_flag == AG_RUNNING_CODE; | |
605 } | |
606 | |
607 static int ag_action_4_r_proc(void) { | |
608 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
609 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
610 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
611 return 1; | |
612 } | |
613 | |
614 static int ag_action_2_proc(void) { | |
615 (PCB).btsx = 0, (PCB).drt = -1; | |
616 if ((PCB).ssx >= 128) { | |
617 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
618 PARSER_STACK_OVERFLOW; | |
619 } | |
620 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
621 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
622 (PCB).ssx++; | |
623 (PCB).sn = (PCB).ag_ap; | |
624 ag_track(); | |
625 return 0; | |
626 } | |
627 | |
628 static int ag_action_9_proc(void) { | |
629 if ((PCB).drt == -1) { | |
630 (PCB).drt=(PCB).token_number; | |
631 (PCB).dssx=(PCB).ssx; | |
632 (PCB).dsn=(PCB).sn; | |
633 } | |
634 ag_prot(); | |
635 (PCB).vs[(PCB).ssx] = ag_null_value; | |
636 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
637 (PCB).ssx++; | |
638 (PCB).sn = (PCB).ag_ap; | |
639 (PCB).rx = 0; | |
640 return (PCB).exit_flag == AG_RUNNING_CODE; | |
641 } | |
642 | |
643 static int ag_action_2_r_proc(void) { | |
644 (PCB).ssx++; | |
645 (PCB).sn = (PCB).ag_ap; | |
646 return 0; | |
647 } | |
648 | |
649 static int ag_action_7_proc(void) { | |
650 --(PCB).ssx; | |
651 (PCB).rx = 0; | |
652 (PCB).exit_flag = AG_SUCCESS_CODE; | |
653 return 0; | |
654 } | |
655 | |
656 static int ag_action_1_proc(void) { | |
657 ag_track(); | |
658 (PCB).exit_flag = AG_SUCCESS_CODE; | |
659 return 0; | |
660 } | |
661 | |
662 static int ag_action_1_r_proc(void) { | |
663 (PCB).exit_flag = AG_SUCCESS_CODE; | |
664 return 0; | |
665 } | |
666 | |
667 static int ag_action_1_s_proc(void) { | |
668 (PCB).exit_flag = AG_SUCCESS_CODE; | |
669 return 0; | |
670 } | |
671 | |
672 static int ag_action_4_proc(void) { | |
673 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
674 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
675 (PCB).btsx = 0, (PCB).drt = -1; | |
676 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
677 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
678 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
679 ag_track(); | |
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_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
690 } | |
691 return 0; | |
692 } | |
693 | |
694 static int ag_action_3_proc(void) { | |
695 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
696 (PCB).btsx = 0, (PCB).drt = -1; | |
697 (PCB).vs[(PCB).ssx] = *(PCB).lab; | |
698 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
699 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
700 ag_track(); | |
701 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
702 ag_ra(); | |
703 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
704 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
705 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
706 do { | |
707 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
708 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
709 else ag_t2 = ag_tx; | |
710 } while (ag_t1 < ag_t2); | |
711 (PCB).ag_ap = ag_pstt[ag_t1]; | |
712 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
713 } | |
714 return 0; | |
715 } | |
716 | |
717 static int ag_action_8_proc(void) { | |
718 ag_undo(); | |
719 (PCB).rx = 0; | |
720 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
721 ag_diagnose(); | |
722 SYNTAX_ERROR; | |
723 {(PCB).rx = 1; ag_track();} | |
724 return (PCB).exit_flag == AG_RUNNING_CODE; | |
725 } | |
726 | |
727 static int ag_action_5_proc(void) { | |
728 int ag_sd = ag_fl[(PCB).ag_ap]; | |
729 (PCB).btsx = 0, (PCB).drt = -1; | |
730 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
731 else { | |
732 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
733 } | |
734 (PCB).rx = 0; | |
735 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
736 ag_ra(); | |
737 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
738 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
739 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
740 do { | |
741 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
742 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
743 else ag_t2 = ag_tx; | |
744 } while (ag_t1 < ag_t2); | |
745 (PCB).ag_ap = ag_pstt[ag_t1]; | |
746 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
747 } | |
748 return (PCB).exit_flag == AG_RUNNING_CODE; | |
749 } | |
750 | |
751 static int ag_action_6_proc(void) { | |
752 int ag_sd = ag_fl[(PCB).ag_ap]; | |
753 (PCB).reduction_token = (test1_token_type) ag_ptt[(PCB).ag_ap]; | |
754 if ((PCB).drt == -1) { | |
755 (PCB).drt=(PCB).token_number; | |
756 (PCB).dssx=(PCB).ssx; | |
757 (PCB).dsn=(PCB).sn; | |
758 } | |
759 if (ag_sd) { | |
760 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
761 } | |
762 else { | |
763 ag_prot(); | |
764 (PCB).vs[(PCB).ssx] = ag_null_value; | |
765 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
766 } | |
767 (PCB).rx = 0; | |
768 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
769 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
770 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
771 do { | |
772 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
773 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
774 else ag_t2 = ag_tx; | |
775 } while (ag_t1 < ag_t2); | |
776 (PCB).ag_ap = ag_pstt[ag_t1]; | |
777 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
778 } | |
779 return (PCB).exit_flag == AG_RUNNING_CODE; | |
780 } | |
781 | |
782 | |
783 void init_test1(void) { | |
784 (PCB).rx = (PCB).fx = 0; | |
785 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
786 (PCB).exit_flag = AG_RUNNING_CODE; | |
787 (PCB).line = FIRST_LINE; | |
788 (PCB).column = FIRST_COLUMN; | |
789 (PCB).btsx = 0, (PCB).drt = -1; | |
790 } | |
791 | |
792 void test1(void) { | |
793 init_test1(); | |
794 (PCB).exit_flag = AG_RUNNING_CODE; | |
795 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
796 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
797 if (ag_tstt[ag_t1]) { | |
798 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
799 if ((PCB).rx < (PCB).fx) { | |
800 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
801 (PCB).token_number = (test1_token_type) AG_TCV((PCB).input_code);} | |
802 else { | |
803 GET_INPUT; | |
804 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
805 (PCB).token_number = (test1_token_type) AG_TCV((PCB).input_code); | |
806 (PCB).rx++; | |
807 } | |
808 if (ag_key_index[(PCB).sn]) { | |
809 unsigned ag_k = ag_key_index[(PCB).sn]; | |
810 int ag_ch = CONVERT_CASE((PCB).input_code); | |
811 if (ag_ch < 255) { | |
812 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
813 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
814 } | |
815 } | |
816 do { | |
817 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
818 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
819 ag_t1 = ag_tx + 1; | |
820 else ag_t2 = ag_tx; | |
821 } while (ag_t1 < ag_t2); | |
822 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
823 ag_t1 = ag_sbe[(PCB).sn]; | |
824 } | |
825 (PCB).ag_ap = ag_pstt[ag_t1]; | |
826 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
827 } | |
828 } | |
829 | |
830 |