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