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