comparison tests/agcl/examples/good/ct.cpp @ 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 * AnaGram, a System for Syntax Directed Programming
3 * C Macro preprocessor
4 * Token Classifier Module
5 *
6 * Copyright 1993-2000 Parsifal Software. All Rights Reserved.
7 *
8 * This software is provided 'as-is', without any express or implied
9 * warranty. In no event will the authors be held liable for any damages
10 * arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose,
13 * including commercial applications, and to alter it and redistribute it
14 * freely, subject to the following restrictions:
15 *
16 * 1. The origin of this software must not be misrepresented; you must not
17 * claim that you wrote the original software. If you use this software
18 * in a product, an acknowledgment in the product documentation would be
19 * appreciated but is not required.
20 * 2. Altered source versions must be plainly marked as such, and must not be
21 * misrepresented as being the original software.
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24
25 #include "mpp.h"
26
27
28 /*
29 * AnaGram, A System for Syntax Directed Programming
30 * File generated by: ...
31 *
32 * AnaGram Parsing Engine
33 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
34 *
35 * This software is provided 'as-is', without any express or implied
36 * warranty. In no event will the authors be held liable for any damages
37 * arising from the use of this software.
38 *
39 * Permission is granted to anyone to use this software for any purpose,
40 * including commercial applications, and to alter it and redistribute it
41 * freely, subject to the following restrictions:
42 *
43 * 1. The origin of this software must not be misrepresented; you must not
44 * claim that you wrote the original software. If you use this software
45 * in a product, an acknowledgment in the product documentation would be
46 * appreciated but is not required.
47 * 2. Altered source versions must be plainly marked as such, and must not be
48 * misrepresented as being the original software.
49 * 3. This notice may not be removed or altered from any source distribution.
50 */
51
52 #ifndef CT_H
53 #include "ct.h"
54 #endif
55
56 #ifndef CT_H
57 #error Mismatched header file
58 #endif
59
60 #include <stdio.h>
61
62 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
63 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
64 #define CONTEXT ((PCB).cs[(PCB).ssx])
65
66
67
68 ct_pcb_type ct_pcb;
69 #define PCB ct_pcb
70
71 token_id ct_value(void);
72
73
74 #line - "ct.syn"
75 // Embedded C
76
77 #define SYNTAX_ERROR // no diagnostic needed
78
79 static char *input_string;
80
81 /*
82
83 id_name() adds the string on the local string_accumulator to the token
84 dictionary and checks to see if the handle corresponds to a reserved
85 word. Otherwise the string is classified simply as a NAME
86
87 */
88
89 static token_id id_name(void) {
90 unsigned handle = td << input_string;
91 token_id id;
92 if (handle <= n_reserved_words) id = reserved_words[handle].id;
93 else id = NAME;
94 return id;
95 }
96
97 /*
98
99 classify_token() is an interface function for the grammar. It sets up
100 the pointer in the parser control block to point to the input string,
101 calls the parser, and returns the token_id determined by the parser if
102 there was no error, and returns "UNRECOGNIZED" if there was an error.
103
104 */
105
106 token_id classify_token(char *string) {
107 input_string = string;
108 PCB.pointer = (unsigned char *) string;
109 ct();
110 return PCB.exit_flag == AG_SUCCESS_CODE ? ct_value() : UNRECOGNIZED;
111 }
112
113 #line - "ct.cpp"
114
115 #ifndef CONVERT_CASE
116 #define CONVERT_CASE(c) (c)
117 #endif
118 #ifndef TAB_SPACING
119 #define TAB_SPACING 8
120 #endif
121 token_id ct_value(void) {
122 token_id returnValue;
123 returnValue = (*(token_id *) &(PCB).vs[(PCB).ssx]);
124 return returnValue;
125 }
126
127 static token_id ag_rp_1(void) {
128 #line - "ct.syn"
129 return id_name();
130 #line - "ct.cpp"
131 }
132
133 static token_id ag_rp_2(void) {
134 #line - "ct.syn"
135 return STRINGliteral;
136 #line - "ct.cpp"
137 }
138
139 static token_id ag_rp_3(void) {
140 #line - "ct.syn"
141 return CHARACTERconstant;
142 #line - "ct.cpp"
143 }
144
145 static token_id ag_rp_4(int p) {
146 #line - "ct.syn"
147 return (token_id) p;
148 #line - "ct.cpp"
149 }
150
151 static token_id ag_rp_5(void) {
152 #line - "ct.syn"
153 return ANDAND;
154 #line - "ct.cpp"
155 }
156
157 static token_id ag_rp_6(void) {
158 #line - "ct.syn"
159 return ANDassign;
160 #line - "ct.cpp"
161 }
162
163 static token_id ag_rp_7(void) {
164 #line - "ct.syn"
165 return ARROW;
166 #line - "ct.cpp"
167 }
168
169 static token_id ag_rp_8(void) {
170 #line - "ct.syn"
171 return CONCAT;
172 #line - "ct.cpp"
173 }
174
175 static token_id ag_rp_9(void) {
176 #line - "ct.syn"
177 return DECR;
178 #line - "ct.cpp"
179 }
180
181 static token_id ag_rp_10(void) {
182 #line - "ct.syn"
183 return DIVassign;
184 #line - "ct.cpp"
185 }
186
187 static token_id ag_rp_11(void) {
188 #line - "ct.syn"
189 return ELLIPSIS;
190 #line - "ct.cpp"
191 }
192
193 static token_id ag_rp_12(void) {
194 #line - "ct.syn"
195 return EQ;
196 #line - "ct.cpp"
197 }
198
199 static token_id ag_rp_13(void) {
200 #line - "ct.syn"
201 return ERassign;
202 #line - "ct.cpp"
203 }
204
205 static token_id ag_rp_14(void) {
206 #line - "ct.syn"
207 return GE;
208 #line - "ct.cpp"
209 }
210
211 static token_id ag_rp_15(void) {
212 #line - "ct.syn"
213 return ICR;
214 #line - "ct.cpp"
215 }
216
217 static token_id ag_rp_16(void) {
218 #line - "ct.syn"
219 return LE;
220 #line - "ct.cpp"
221 }
222
223 static token_id ag_rp_17(void) {
224 #line - "ct.syn"
225 return LS;
226 #line - "ct.cpp"
227 }
228
229 static token_id ag_rp_18(void) {
230 #line - "ct.syn"
231 return LSassign;
232 #line - "ct.cpp"
233 }
234
235 static token_id ag_rp_19(void) {
236 #line - "ct.syn"
237 return MODassign;
238 #line - "ct.cpp"
239 }
240
241 static token_id ag_rp_20(void) {
242 #line - "ct.syn"
243 return MINUSassign;
244 #line - "ct.cpp"
245 }
246
247 static token_id ag_rp_21(void) {
248 #line - "ct.syn"
249 return MULTassign;
250 #line - "ct.cpp"
251 }
252
253 static token_id ag_rp_22(void) {
254 #line - "ct.syn"
255 return NE;
256 #line - "ct.cpp"
257 }
258
259 static token_id ag_rp_23(void) {
260 #line - "ct.syn"
261 return ORassign;
262 #line - "ct.cpp"
263 }
264
265 static token_id ag_rp_24(void) {
266 #line - "ct.syn"
267 return OROR;
268 #line - "ct.cpp"
269 }
270
271 static token_id ag_rp_25(void) {
272 #line - "ct.syn"
273 return PLUSassign;
274 #line - "ct.cpp"
275 }
276
277 static token_id ag_rp_26(void) {
278 #line - "ct.syn"
279 return RS;
280 #line - "ct.cpp"
281 }
282
283 static token_id ag_rp_27(void) {
284 #line - "ct.syn"
285 return RSassign;
286 #line - "ct.cpp"
287 }
288
289 static token_id ag_rp_28(void) {
290 #line - "ct.syn"
291 return FLOATconstant;
292 #line - "ct.cpp"
293 }
294
295 static token_id ag_rp_29(void) {
296 #line - "ct.syn"
297 return OCTconstant;
298 #line - "ct.cpp"
299 }
300
301 static token_id ag_rp_30(void) {
302 #line - "ct.syn"
303 return DECconstant;
304 #line - "ct.cpp"
305 }
306
307 static token_id ag_rp_31(void) {
308 #line - "ct.syn"
309 return HEXconstant;
310 #line - "ct.cpp"
311 }
312
313
314 #define READ_COUNTS
315 #define WRITE_COUNTS
316 #undef V
317 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
318 #undef VS
319 #define VS(i) (PCB).vs[(PCB).ssx + i]
320
321 #ifndef GET_CONTEXT
322 #define GET_CONTEXT CONTEXT = (PCB).input_context
323 #endif
324
325 typedef enum {
326 ag_action_1,
327 ag_action_2,
328 ag_action_3,
329 ag_action_4,
330 ag_action_5,
331 ag_action_6,
332 ag_action_7,
333 ag_action_8,
334 ag_action_9,
335 ag_action_10,
336 ag_action_11,
337 ag_action_12
338 } ag_parser_action;
339
340
341 #ifndef NULL_VALUE_INITIALIZER
342 #define NULL_VALUE_INITIALIZER = { 0 }
343 #endif
344
345 static ct_vs_type const ag_null_value NULL_VALUE_INITIALIZER;
346
347 static const unsigned char ag_rpx[] = {
348 0, 0, 1, 0, 0, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
349 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 0, 0, 0,
350 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29,
351 30, 31
352 };
353
354 #define AG_TCV(x) ag_tcv[(x)]
355
356 static const unsigned char ag_tcv[] = {
357 3, 61, 61, 61, 61, 61, 61, 61, 61, 61, 55, 61, 61, 61, 61, 61, 61, 61,
358 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 23, 51, 15,
359 61, 21, 11, 57, 61, 61, 22, 19, 61, 13, 17, 16, 43, 62, 62, 62, 62, 62,
360 62, 62, 36, 36, 61, 61, 20, 12, 14, 61, 61, 63, 63, 63, 63, 37, 28, 64,
361 64, 64, 64, 64, 29, 64, 64, 64, 64, 64, 64, 64, 64, 49, 64, 64, 46, 64,
362 64, 61, 53, 61, 18, 64, 61, 63, 63, 63, 63, 37, 28, 64, 64, 64, 64, 64,
363 29, 64, 64, 64, 64, 64, 64, 64, 64, 49, 64, 64, 46, 64, 64, 61, 24, 61,
364 61, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
365 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
366 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
367 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
368 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
369 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
370 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
371 65, 65, 65, 65
372 };
373
374 #ifndef SYNTAX_ERROR
375 #define SYNTAX_ERROR fprintf(stderr,"%s\n", (PCB).error_message)
376 #endif
377
378 #ifndef PARSER_STACK_OVERFLOW
379 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
380 "\nParser stack overflow\n");}
381 #endif
382
383 #ifndef REDUCTION_TOKEN_ERROR
384 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
385 "\nReduction token error\n");}
386 #endif
387
388
389 #ifndef INPUT_CODE
390 #define INPUT_CODE(T) (T)
391 #endif
392
393
394 static void ag_prot(void) {
395 int ag_k;
396 ag_k = 128 - ++(PCB).btsx;
397 if (ag_k <= (PCB).ssx) {
398 (PCB).exit_flag = AG_STACK_ERROR_CODE;
399 PARSER_STACK_OVERFLOW;
400 return;
401 }
402 (PCB).bts[(PCB).btsx] = (PCB).sn;
403 (PCB).bts[ag_k] = (PCB).ssx;
404 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
405 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
406 }
407
408 static void ag_undo(void) {
409 if ((PCB).drt == -1) return;
410 while ((PCB).btsx) {
411 int ag_k = 128 - (PCB).btsx;
412 (PCB).sn = (PCB).bts[(PCB).btsx--];
413 (PCB).ssx = (PCB).bts[ag_k];
414 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
415 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
416 }
417 (PCB).token_number = (ct_token_type) (PCB).drt;
418 (PCB).ssx = (PCB).dssx;
419 (PCB).sn = (PCB).dsn;
420 (PCB).drt = -1;
421 }
422
423
424 static const unsigned char ag_tstt[] = {
425 64,63,62,61,57,55,53,51,49,46,43,37,36,29,28,24,23,22,21,20,19,18,17,16,15,
426 14,13,12,11,0,1,2,4,5,6,7,8,9,25,27,30,32,33,34,39,40,41,45,50,56,
427 46,0,
428 62,43,37,36,17,0,31,
429 62,43,37,36,0,31,
430 63,62,43,37,36,28,0,
431 62,43,37,36,17,0,31,
432 62,43,36,17,0,
433 24,12,0,
434 12,0,
435 12,0,
436 12,0,
437 20,12,0,
438 19,12,0,
439 14,12,0,
440 12,0,
441 12,0,
442 62,43,36,17,0,
443 12,0,
444 15,0,
445 14,13,12,0,
446 12,11,0,
447 65,64,63,62,61,57,53,51,49,46,43,37,36,29,28,24,23,22,21,20,19,18,17,16,15,
448 14,13,12,11,0,
449 65,64,63,62,61,57,53,51,49,46,43,37,36,29,28,24,23,22,21,20,19,18,17,16,15,
450 14,13,12,11,0,
451 49,29,0,42,
452 49,29,0,42,
453 49,29,0,42,
454 29,28,3,0,26,
455 64,63,62,49,46,43,37,36,29,28,0,
456 3,0,
457 63,62,43,37,36,28,0,
458 62,43,36,19,13,0,38,
459 62,43,36,0,
460 62,43,36,0,
461 62,43,36,0,
462 12,0,
463 12,0,
464 17,0,
465 65,64,63,62,61,57,55,53,51,49,46,43,37,36,29,28,24,23,22,21,20,19,18,17,16,
466 15,14,13,12,11,0,
467 65,64,63,62,61,57,55,53,51,49,46,43,37,36,29,28,24,23,22,21,20,19,18,17,16,
468 15,14,13,12,11,0,
469 62,43,36,0,
470 62,43,36,0,
471
472 };
473
474
475 static unsigned const char ag_astt[314] = {
476 1,1,1,2,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,7,0,1,1,1,1,2,2,
477 1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,9,9,1,9,3,7,1,9,9,1,9,5,1,9,9,9,9,9,9,5,9,9,
478 1,9,3,5,1,9,9,3,3,5,2,2,4,2,4,2,4,2,4,1,2,4,2,2,4,1,2,4,2,4,2,4,3,3,3,1,4,
479 2,4,2,4,2,2,2,4,2,2,4,9,9,9,9,9,3,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
480 9,9,9,7,9,9,9,9,9,9,1,3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,7,9,9,4,
481 3,9,9,4,3,9,9,4,3,2,2,5,7,2,9,9,9,9,9,9,9,9,9,9,4,3,7,3,3,3,3,3,3,7,8,8,8,
482 1,1,7,1,9,9,9,5,9,9,9,5,9,9,9,5,2,4,2,4,2,7,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
483 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,7,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
484 3,3,3,3,3,3,3,3,3,7,3,3,3,7,3,3,3,7
485 };
486
487
488 static const unsigned char ag_pstt[] = {
489 27,27,5,8,21,8,8,22,27,27,1,27,5,27,27,7,8,9,10,11,12,14,16,17,18,13,19,15,
490 20,0,0,28,27,28,28,5,6,28,26,26,3,2,5,6,25,24,23,4,22,21,
491 29,58,
492 47,47,30,47,41,2,31,
493 45,45,30,45,37,32,
494 63,63,63,63,63,63,60,
495 67,67,30,67,43,64,33,
496 59,59,46,42,56,
497 28,27,8,
498 26,8,
499 25,8,
500 23,8,
501 34,20,8,
502 19,29,8,
503 35,18,8,
504 17,8,
505 16,8,
506 44,44,44,36,8,
507 14,8,
508 12,8,
509 11,13,24,8,
510 10,9,8,
511 77,77,77,77,77,75,37,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
512 77,77,77,77,21,
513 72,72,72,72,72,72,38,70,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,
514 72,72,72,72,22,
515 61,61,55,61,
516 65,65,54,65,
517 57,57,53,57,
518 32,32,34,26,32,
519 81,81,81,81,81,81,81,81,81,81,2,
520 1,28,
521 62,62,62,62,62,62,29,
522 39,39,39,39,40,30,39,
523 52,52,52,39,
524 52,52,52,38,
525 52,52,52,40,
526 22,21,
527 31,30,
528 15,36,
529 78,78,78,78,78,78,79,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,
530 78,78,78,78,78,37,
531 73,73,73,73,73,73,74,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,73,
532 73,73,73,73,73,38,
533 51,51,51,39,
534 48,48,48,40,
535
536 };
537
538
539 static const unsigned short ag_sbt[] = {
540 0, 50, 52, 59, 65, 72, 79, 84, 87, 89, 91, 93, 96, 99,
541 102, 104, 106, 111, 113, 115, 119, 122, 152, 182, 186, 190, 194, 199,
542 210, 212, 219, 226, 230, 234, 238, 240, 242, 244, 275, 306, 310, 314
543 };
544
545
546 static const unsigned short ag_sbe[] = {
547 29, 51, 57, 63, 71, 77, 83, 86, 88, 90, 92, 95, 98, 101,
548 103, 105, 110, 112, 114, 118, 121, 151, 181, 184, 188, 192, 197, 209,
549 211, 218, 224, 229, 233, 237, 239, 241, 243, 274, 305, 309, 313, 314
550 };
551
552
553 static const unsigned char ag_fl[] = {
554 1,2,1,1,1,1,1,1,1,2,2,2,2,2,2,3,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,3,2,1,0,
555 1,1,1,2,2,2,2,2,2,2,2,2,2,3,0,1,3,2,1,1,1,1,2,1,2,1,2,3,2,1,2,1,2,1,1,
556 2,1,2,3,3,2,1,2,3,3,1,2
557 };
558
559 static const unsigned char ag_ptt[] = {
560 0, 1, 2, 2, 2, 2, 2, 2, 2, 9, 9, 9, 9, 9, 9, 9, 9, 9,
561 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 25, 26, 26,
562 26, 27, 27, 27, 27, 30, 30, 30, 30, 30, 32, 32, 31, 38, 38, 31, 31, 6,
563 6, 6, 39, 39, 34, 34, 41, 41, 45, 45, 40, 40, 33, 33, 42, 42, 7, 50,
564 50, 50, 50, 8, 56, 56, 56, 56, 4, 4
565 };
566
567
568 static void ag_ra(void)
569 {
570 switch(ag_rpx[(PCB).ag_ap]) {
571 case 1: V(0,(token_id *)) = ag_rp_1(); break;
572 case 2: V(0,(token_id *)) = ag_rp_2(); break;
573 case 3: V(0,(token_id *)) = ag_rp_3(); break;
574 case 4: V(0,(token_id *)) = ag_rp_4(V(0,(int *))); break;
575 case 5: V(0,(token_id *)) = ag_rp_5(); break;
576 case 6: V(0,(token_id *)) = ag_rp_6(); break;
577 case 7: V(0,(token_id *)) = ag_rp_7(); break;
578 case 8: V(0,(token_id *)) = ag_rp_8(); break;
579 case 9: V(0,(token_id *)) = ag_rp_9(); break;
580 case 10: V(0,(token_id *)) = ag_rp_10(); break;
581 case 11: V(0,(token_id *)) = ag_rp_11(); break;
582 case 12: V(0,(token_id *)) = ag_rp_12(); break;
583 case 13: V(0,(token_id *)) = ag_rp_13(); break;
584 case 14: V(0,(token_id *)) = ag_rp_14(); break;
585 case 15: V(0,(token_id *)) = ag_rp_15(); break;
586 case 16: V(0,(token_id *)) = ag_rp_16(); break;
587 case 17: V(0,(token_id *)) = ag_rp_17(); break;
588 case 18: V(0,(token_id *)) = ag_rp_18(); break;
589 case 19: V(0,(token_id *)) = ag_rp_19(); break;
590 case 20: V(0,(token_id *)) = ag_rp_20(); break;
591 case 21: V(0,(token_id *)) = ag_rp_21(); break;
592 case 22: V(0,(token_id *)) = ag_rp_22(); break;
593 case 23: V(0,(token_id *)) = ag_rp_23(); break;
594 case 24: V(0,(token_id *)) = ag_rp_24(); break;
595 case 25: V(0,(token_id *)) = ag_rp_25(); break;
596 case 26: V(0,(token_id *)) = ag_rp_26(); break;
597 case 27: V(0,(token_id *)) = ag_rp_27(); break;
598 case 28: V(0,(token_id *)) = ag_rp_28(); break;
599 case 29: V(0,(token_id *)) = ag_rp_29(); break;
600 case 30: V(0,(token_id *)) = ag_rp_30(); break;
601 case 31: V(0,(token_id *)) = ag_rp_31(); break;
602 }
603 (PCB).la_ptr = (PCB).pointer;
604 }
605
606 static int ag_action_1_r_proc(void);
607 static int ag_action_2_r_proc(void);
608 static int ag_action_3_r_proc(void);
609 static int ag_action_4_r_proc(void);
610 static int ag_action_1_s_proc(void);
611 static int ag_action_3_s_proc(void);
612 static int ag_action_1_proc(void);
613 static int ag_action_2_proc(void);
614 static int ag_action_3_proc(void);
615 static int ag_action_4_proc(void);
616 static int ag_action_5_proc(void);
617 static int ag_action_6_proc(void);
618 static int ag_action_7_proc(void);
619 static int ag_action_8_proc(void);
620 static int ag_action_9_proc(void);
621 static int ag_action_10_proc(void);
622 static int ag_action_11_proc(void);
623 static int ag_action_8_proc(void);
624
625
626 static int (*const ag_r_procs_scan[])(void) = {
627 ag_action_1_r_proc,
628 ag_action_2_r_proc,
629 ag_action_3_r_proc,
630 ag_action_4_r_proc
631 };
632
633 static int (*const ag_s_procs_scan[])(void) = {
634 ag_action_1_s_proc,
635 ag_action_2_r_proc,
636 ag_action_3_s_proc,
637 ag_action_4_r_proc
638 };
639
640 static int (*const ag_gt_procs_scan[])(void) = {
641 ag_action_1_proc,
642 ag_action_2_proc,
643 ag_action_3_proc,
644 ag_action_4_proc,
645 ag_action_5_proc,
646 ag_action_6_proc,
647 ag_action_7_proc,
648 ag_action_8_proc,
649 ag_action_9_proc,
650 ag_action_10_proc,
651 ag_action_11_proc,
652 ag_action_8_proc
653 };
654
655
656 static int ag_action_10_proc(void) {
657 int ag_t = (PCB).token_number;
658 (PCB).btsx = 0, (PCB).drt = -1;
659 do {
660 (PCB).pointer = (PCB).la_ptr;
661 (PCB).token_number = (ct_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
662 (PCB).la_ptr++;
663 } while ((PCB).token_number == (ct_token_type) ag_t);
664 (PCB).la_ptr = (PCB).pointer;
665 return 1;
666 }
667
668 static int ag_action_11_proc(void) {
669 int ag_t = (PCB).token_number;
670
671 (PCB).btsx = 0, (PCB).drt = -1;
672 do {
673 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
674 (PCB).ssx--;
675 (PCB).pointer = (PCB).la_ptr;
676 ag_ra();
677 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
678 (PCB).ssx++;
679 (PCB).token_number = (ct_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
680 (PCB).la_ptr++;
681 }
682 while ((PCB).token_number == (ct_token_type) ag_t);
683 (PCB).la_ptr = (PCB).pointer;
684 return 1;
685 }
686
687 static int ag_action_3_r_proc(void) {
688 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
689 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
690 (PCB).btsx = 0, (PCB).drt = -1;
691 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
692 ag_ra();
693 return (PCB).exit_flag == AG_RUNNING_CODE;
694 }
695
696 static int ag_action_3_s_proc(void) {
697 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
698 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
699 (PCB).btsx = 0, (PCB).drt = -1;
700 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
701 ag_ra();
702 return (PCB).exit_flag == AG_RUNNING_CODE;
703 }
704
705 static int ag_action_4_r_proc(void) {
706 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
707 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
708 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
709 return 1;
710 }
711
712 static int ag_action_2_proc(void) {
713 (PCB).btsx = 0, (PCB).drt = -1;
714 if ((PCB).ssx >= 128) {
715 (PCB).exit_flag = AG_STACK_ERROR_CODE;
716 PARSER_STACK_OVERFLOW;
717 }
718 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
719 (PCB).ss[(PCB).ssx] = (PCB).sn;
720 (PCB).ssx++;
721 (PCB).sn = (PCB).ag_ap;
722 (PCB).pointer = (PCB).la_ptr;
723 return 0;
724 }
725
726 static int ag_action_9_proc(void) {
727 if ((PCB).drt == -1) {
728 (PCB).drt=(PCB).token_number;
729 (PCB).dssx=(PCB).ssx;
730 (PCB).dsn=(PCB).sn;
731 }
732 ag_prot();
733 (PCB).vs[(PCB).ssx] = ag_null_value;
734 (PCB).ss[(PCB).ssx] = (PCB).sn;
735 (PCB).ssx++;
736 (PCB).sn = (PCB).ag_ap;
737 (PCB).la_ptr = (PCB).pointer;
738 return (PCB).exit_flag == AG_RUNNING_CODE;
739 }
740
741 static int ag_action_2_r_proc(void) {
742 (PCB).ssx++;
743 (PCB).sn = (PCB).ag_ap;
744 return 0;
745 }
746
747 static int ag_action_7_proc(void) {
748 --(PCB).ssx;
749 (PCB).la_ptr = (PCB).pointer;
750 (PCB).exit_flag = AG_SUCCESS_CODE;
751 return 0;
752 }
753
754 static int ag_action_1_proc(void) {
755 (PCB).pointer = (PCB).la_ptr;
756 (PCB).exit_flag = AG_SUCCESS_CODE;
757 return 0;
758 }
759
760 static int ag_action_1_r_proc(void) {
761 (PCB).exit_flag = AG_SUCCESS_CODE;
762 return 0;
763 }
764
765 static int ag_action_1_s_proc(void) {
766 (PCB).exit_flag = AG_SUCCESS_CODE;
767 return 0;
768 }
769
770 static int ag_action_4_proc(void) {
771 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
772 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
773 (PCB).btsx = 0, (PCB).drt = -1;
774 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
775 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
776 else (PCB).ss[(PCB).ssx] = (PCB).sn;
777 (PCB).pointer = (PCB).la_ptr;
778 while ((PCB).exit_flag == AG_RUNNING_CODE) {
779 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
780 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
781 do {
782 unsigned ag_tx = (ag_t1 + ag_t2)/2;
783 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
784 else ag_t2 = ag_tx;
785 } while (ag_t1 < ag_t2);
786 (PCB).ag_ap = ag_pstt[ag_t1];
787 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
788 }
789 return 0;
790 }
791
792 static int ag_action_3_proc(void) {
793 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
794 (PCB).btsx = 0, (PCB).drt = -1;
795 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer;
796 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
797 else (PCB).ss[(PCB).ssx] = (PCB).sn;
798 (PCB).pointer = (PCB).la_ptr;
799 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
800 ag_ra();
801 while ((PCB).exit_flag == AG_RUNNING_CODE) {
802 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
803 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
804 do {
805 unsigned ag_tx = (ag_t1 + ag_t2)/2;
806 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
807 else ag_t2 = ag_tx;
808 } while (ag_t1 < ag_t2);
809 (PCB).ag_ap = ag_pstt[ag_t1];
810 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
811 }
812 return 0;
813 }
814
815 static int ag_action_8_proc(void) {
816 ag_undo();
817 (PCB).la_ptr = (PCB).pointer;
818 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
819 SYNTAX_ERROR;
820 (PCB).la_ptr = ++(PCB).pointer;
821 return (PCB).exit_flag == AG_RUNNING_CODE;
822 }
823
824 static int ag_action_5_proc(void) {
825 int ag_sd = ag_fl[(PCB).ag_ap];
826 (PCB).btsx = 0, (PCB).drt = -1;
827 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
828 else {
829 (PCB).ss[(PCB).ssx] = (PCB).sn;
830 }
831 (PCB).la_ptr = (PCB).pointer;
832 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
833 ag_ra();
834 while ((PCB).exit_flag == AG_RUNNING_CODE) {
835 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
836 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
837 do {
838 unsigned ag_tx = (ag_t1 + ag_t2)/2;
839 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
840 else ag_t2 = ag_tx;
841 } while (ag_t1 < ag_t2);
842 (PCB).ag_ap = ag_pstt[ag_t1];
843 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
844 }
845 return (PCB).exit_flag == AG_RUNNING_CODE;
846 }
847
848 static int ag_action_6_proc(void) {
849 int ag_sd = ag_fl[(PCB).ag_ap];
850 (PCB).reduction_token = (ct_token_type) ag_ptt[(PCB).ag_ap];
851 if ((PCB).drt == -1) {
852 (PCB).drt=(PCB).token_number;
853 (PCB).dssx=(PCB).ssx;
854 (PCB).dsn=(PCB).sn;
855 }
856 if (ag_sd) {
857 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
858 }
859 else {
860 ag_prot();
861 (PCB).vs[(PCB).ssx] = ag_null_value;
862 (PCB).ss[(PCB).ssx] = (PCB).sn;
863 }
864 (PCB).la_ptr = (PCB).pointer;
865 while ((PCB).exit_flag == AG_RUNNING_CODE) {
866 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
867 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
868 do {
869 unsigned ag_tx = (ag_t1 + ag_t2)/2;
870 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
871 else ag_t2 = ag_tx;
872 } while (ag_t1 < ag_t2);
873 (PCB).ag_ap = ag_pstt[ag_t1];
874 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
875 }
876 return (PCB).exit_flag == AG_RUNNING_CODE;
877 }
878
879
880 void init_ct(void) {
881 (PCB).la_ptr = (PCB).pointer;
882 (PCB).error_message = "Syntax Error";
883 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
884 (PCB).exit_flag = AG_RUNNING_CODE;
885 (PCB).btsx = 0, (PCB).drt = -1;
886 }
887
888 void ct(void) {
889 init_ct();
890 (PCB).exit_flag = AG_RUNNING_CODE;
891 while ((PCB).exit_flag == AG_RUNNING_CODE) {
892 unsigned ag_t1 = ag_sbt[(PCB).sn];
893 if (ag_tstt[ag_t1]) {
894 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
895 (PCB).token_number = (ct_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
896 (PCB).la_ptr++;
897 do {
898 unsigned ag_tx = (ag_t1 + ag_t2)/2;
899 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
900 ag_t1 = ag_tx + 1;
901 else ag_t2 = ag_tx;
902 } while (ag_t1 < ag_t2);
903 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number)
904 ag_t1 = ag_sbe[(PCB).sn];
905 }
906 (PCB).ag_ap = ag_pstt[ag_t1];
907 (ag_gt_procs_scan[ag_astt[ag_t1]])();
908 }
909 }
910
911