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