comparison tests/agcl/contrib/good/parse.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 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1993-1994 Steve Holland. All rights reserved.
4 * See the file COPYING for license and usage terms.
5 */
6 /* Embedded C code */
7 #include <exec/lists.h>
8 #include <intuition/classes.h>
9 #include <proto/intuition.h>
10 #include "OOLib.h"
11 #include "Expr.h"
12 #include "PushString.h"
13 #include "ClassManager.h"
14 #include "Driver/VariableClass.h"
15 #include "Number.h"
16 #include "Util.h"
17
18 struct List ExprList;
19
20 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", (PCB).error_message, (PCB).line, (PCB).column)
21 #define PARSER_STACK_OVERFLOW {fprintf(stderr, "\nParser stack overflow, line %d, column %d\n", (PCB).line, (PCB).column);}
22 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, "\nReduction token error, line %d, column %d\n", (PCB).line, (PCB).column);}
23
24 Object *VariableProto=NULL; /* remember to initialize this */
25
26 void Prepare_parse(void)
27 {
28 VariableProto=NewObject(FindOOClass("numberclass"),NULL,NM_ID,VARIABLECLASS_ID,TAG_END);
29 if (!VariableProto) Warning(183,"Unable to create prototype variable object");
30 if (!ExprList.lh_Head) NewList(&ExprList);
31 }
32
33 void End_parse(void)
34 {
35 if (VariableProto) DisposeObject(VariableProto);
36 VariableProto=NULL;
37 }
38
39
40 /*
41 * AnaGram, A System for Syntax Directed Programming
42 * File generated by: ...
43 *
44 * AnaGram Parsing Engine
45 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
46 *
47 * This software is provided 'as-is', without any express or implied
48 * warranty. In no event will the authors be held liable for any damages
49 * arising from the use of this software.
50 *
51 * Permission is granted to anyone to use this software for any purpose,
52 * including commercial applications, and to alter it and redistribute it
53 * freely, subject to the following restrictions:
54 *
55 * 1. The origin of this software must not be misrepresented; you must not
56 * claim that you wrote the original software. If you use this software
57 * in a product, an acknowledgment in the product documentation would be
58 * appreciated but is not required.
59 * 2. Altered source versions must be plainly marked as such, and must not be
60 * misrepresented as being the original software.
61 * 3. This notice may not be removed or altered from any source distribution.
62 */
63
64 #ifndef PARSE_H
65 #include "parse.h"
66 #endif
67
68 #ifndef PARSE_H
69 #error Mismatched header file
70 #endif
71
72 #include <ctype.h>
73 #include <stdio.h>
74
75 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
76 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
77 #define CONTEXT ((PCB).cs[(PCB).ssx])
78
79
80
81 parse_pcb_type parse_pcb;
82 #define PCB parse_pcb
83
84 #ifndef CONVERT_CASE
85
86 static const char agCaseTable[31] = {
87 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
88 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
89 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0,
90 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
91 };
92
93 static int agConvertCase(int c) {
94 if (c >= 'a' && c <= 'z') return c ^= 0x20;
95 if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0];
96 return c;
97 }
98
99 #define CONVERT_CASE(c) agConvertCase(c)
100
101 #endif
102
103
104 #ifndef TAB_SPACING
105 #define TAB_SPACING 8
106 #endif
107
108 static void ag_rp_1(void) {
109 #line - "parse.syn"
110 PCB.exit_flag=AG_SUCCESS_CODE;
111 #line - "parse.c"
112 }
113
114 static void ag_rp_2(void) {
115 #line - "parse.syn"
116 Object *Result;
117 struct ExprNode *Node;
118 char *String=NULL;
119 Result=EvalExpr(&ExprList);
120 if (Result) {
121 GetAttr(NM_NumberString,Result,(ULONG *)&String);
122 if (String) printf("%s\n",String);
123 DisposeObject(Result);
124 }
125
126 while (Node=(struct ExprNode *)RemHead(&ExprList)) {
127 if (Node->Op != OP_FUNC && Node->Data) DisposeObject(Node->Data);
128 Free(Node);
129 }
130
131 #line - "parse.c"
132 }
133
134 static void ag_rp_3(int a) {
135 #line - "parse.syn"
136 ReverseTopExprStack(&ExprList,a);Push(&ExprList,OP_GROUP,a,NULL);
137 #line - "parse.c"
138 }
139
140 static void ag_rp_4(void) {
141 #line - "parse.syn"
142 struct Locale *Locale;DoMethod(VariableProto,VCM_NEWLOCALE,&Locale);
143 #line - "parse.c"
144 }
145
146 static struct LocaleNode * ag_rp_5(void) {
147 #line - "parse.syn"
148 struct LocaleNode *Locale;DoMethod(VariableProto,VCM_TAKELOCALE,NULL,&Locale);return Locale;
149 #line - "parse.c"
150 }
151
152 static void ag_rp_6(struct String * Str) {
153 #line - "parse.syn"
154 if (Str && GetString(Str)) {
155 NewObject(FindOOClass("numberclass"),NULL,
156 NM_ID,VARIABLECLASS_ID,
157 VA_Create,TRUE,
158 NM_NumberString,GetString(Str),
159 VA_NoObject,TRUE,
160 TAG_END);
161 DeleteString(Str);
162 }
163 else ParsePanic(PP_MEM);
164
165 #line - "parse.c"
166 }
167
168 static void ag_rp_7(struct String * Str, Object * Num) {
169 #line - "parse.syn"
170 Object *Const;
171 if (Str && GetString(Str)) {
172 Const=NewObject(FindOOClass("numberclass"),NULL,
173 NM_ID,VARIABLECLASS_ID,
174 NM_NumberString,GetString(Str),
175 VA_Constant,TRUE,
176 VA_Create,TRUE,
177 TAG_END);
178 DeleteString(Str);
179 if (Const && Num) DoMethod(Const,VCM_ASSIGNFORCE,Num);
180 if (Const) DisposeObject(Const);
181 }
182 else ParsePanic(PP_MEM);
183 if (Num) DisposeObject(Num);
184
185 #line - "parse.c"
186 }
187
188 static void ag_rp_8(struct String * Str) {
189 #line - "parse.syn"
190 if (Str && GetString(Str)) {
191 NewObject(FindOOClass("numberclass"),NULL,
192 NM_ID,VARIABLECLASS_ID,
193 VA_Create,TRUE,
194 NM_NumberString,GetString(Str),
195 VA_NoObject,TRUE,
196 TAG_END);
197 DeleteString(Str);
198 }
199 else ParsePanic(PP_MEM);
200
201 #line - "parse.c"
202 }
203
204 static void ag_rp_9(struct String * Str) {
205 #line - "parse.syn"
206 if (Str && GetString(Str)) {
207 NewObject(FindOOClass("numberclass"),NULL,
208 NM_ID,VARIABLECLASS_ID,
209 NM_NumberString,GetString(Str),
210 VA_ByReference,TRUE,
211 VA_Create,TRUE,
212 VA_NoObject,TRUE,
213 TAG_END);
214 DeleteString(Str);
215 }
216 else ParsePanic(PP_MEM);
217
218 #line - "parse.c"
219 }
220
221 static void ag_rp_10(struct String * Str, Object * Num) {
222 #line - "parse.syn"
223 Object *Const;
224 if (Str && GetString(Str)) {
225 Const=NewObject(FindOOClass("numberclass"),NULL,
226 NM_ID,VARIABLECLASS_ID,
227 NM_NumberString,GetString(Str),
228 VA_Constant,TRUE,
229 VA_Create,TRUE,
230 TAG_END);
231 if (Const && Num) DoMethod(Const,VCM_ASSIGNFORCE,Num);
232 if (Const) DisposeObject(Const);
233 DeleteString(Str);
234
235 }
236 else ParsePanic(PP_MEM);
237 if (Num) DisposeObject(Num);
238
239 #line - "parse.c"
240 }
241
242 static void ag_rp_11(void) {
243 #line - "parse.syn"
244 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_GT);
245 #line - "parse.c"
246 }
247
248 static void ag_rp_12(void) {
249 #line - "parse.syn"
250 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_LT);
251 #line - "parse.c"
252 }
253
254 static void ag_rp_13(void) {
255 #line - "parse.syn"
256 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_COMP);
257 #line - "parse.c"
258 }
259
260 static void ag_rp_14(void) {
261 #line - "parse.syn"
262 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_GTEQ);
263 #line - "parse.c"
264 }
265
266 static void ag_rp_15(void) {
267 #line - "parse.syn"
268 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_LTEQ);
269 #line - "parse.c"
270 }
271
272 static int ag_rp_16(void) {
273 #line - "parse.syn"
274 return 1;
275 #line - "parse.c"
276 }
277
278 static int ag_rp_17(void) {
279 #line - "parse.syn"
280 return 1;
281 #line - "parse.c"
282 }
283
284 static int ag_rp_18(int n) {
285 #line - "parse.syn"
286 return n+1;
287 #line - "parse.c"
288 }
289
290 static void ag_rp_19(Object * s) {
291 #line - "parse.syn"
292 Push(&ExprList,OP_ASSIGN,0,s);
293 #line - "parse.c"
294 }
295
296 static void ag_rp_20(struct String * f, unsigned n) {
297 #line - "parse.syn"
298 ReverseTopExprStack(&ExprList,n);Push(&ExprList,OP_FUNC,n,GetString(f));DeleteString(f);
299 #line - "parse.c"
300 }
301
302 static void ag_rp_21(void) {
303 #line - "parse.syn"
304 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_ADD);
305 #line - "parse.c"
306 }
307
308 static void ag_rp_22(void) {
309 #line - "parse.syn"
310 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_SUB);
311 #line - "parse.c"
312 }
313
314 static unsigned ag_rp_23(void) {
315 #line - "parse.syn"
316 return 0;
317 #line - "parse.c"
318 }
319
320 static unsigned ag_rp_24(void) {
321 #line - "parse.syn"
322 return 1;
323 #line - "parse.c"
324 }
325
326 static unsigned ag_rp_25(unsigned a) {
327 #line - "parse.syn"
328 return a+1;
329 #line - "parse.c"
330 }
331
332 static void ag_rp_26(void) {
333 #line - "parse.syn"
334 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_MUL);
335 #line - "parse.c"
336 }
337
338 static void ag_rp_27(void) {
339 #line - "parse.syn"
340 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_DIV);
341 #line - "parse.c"
342 }
343
344 static void ag_rp_28(void) {
345 #line - "parse.syn"
346 Push(&ExprList,OP_FUNC,1,FUNC_OPPOSITE);
347 #line - "parse.c"
348 }
349
350 static void ag_rp_29(void) {
351 #line - "parse.syn"
352 ReverseTopExprStack(&ExprList,2);Push(&ExprList,OP_FUNC,2,FUNC_POW);
353 #line - "parse.c"
354 }
355
356 static void ag_rp_30(Object * Vari) {
357 #line - "parse.syn"
358 Push(&ExprList,OP_VAR,1,Vari);
359 #line - "parse.c"
360 }
361
362 static Object * ag_rp_31(struct String * Str) {
363 #line - "parse.syn"
364 Object *Result;
365 if (Str && GetString(Str)) {
366 DiscardBlanks(Str);
367 Result=NewObject(FindOOClass("numberclass"),NULL,
368 NM_NumberString,GetString(Str),
369 TAG_END);
370 DeleteString(Str);
371 if (Result) return Result;
372 }
373 ParsePanic(PP_MEM);
374 return NULL;
375
376 #line - "parse.c"
377 }
378
379 static struct String * ag_rp_32(struct String * s) {
380 #line - "parse.syn"
381 return s;
382 #line - "parse.c"
383 }
384
385 static struct String * ag_rp_33(int c) {
386 #line - "parse.syn"
387 struct String *String;String=CreateString();StringInsChar(String,strlen(GetString(String)),c);return String;
388 #line - "parse.c"
389 }
390
391 static struct String * ag_rp_34(struct String * String, int c) {
392 #line - "parse.syn"
393 return StringInsChar(String,strlen(GetString(String)),c);
394 #line - "parse.c"
395 }
396
397 static struct String * ag_rp_35(struct String * String, int c) {
398 #line - "parse.syn"
399 return StringInsChar(String,strlen(GetString(String)),c);
400 #line - "parse.c"
401 }
402
403
404 #define READ_COUNTS
405 #define WRITE_COUNTS
406 #undef V
407 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i]))
408 #undef VS
409 #define VS(i) (PCB).vs[(PCB).ssx + i]
410
411 #ifndef GET_CONTEXT
412 #define GET_CONTEXT CONTEXT = (PCB).input_context
413 #endif
414
415 typedef enum {
416 ag_action_1,
417 ag_action_2,
418 ag_action_3,
419 ag_action_4,
420 ag_action_5,
421 ag_action_6,
422 ag_action_7,
423 ag_action_8,
424 ag_action_9,
425 ag_action_10,
426 ag_action_11,
427 ag_action_12
428 } ag_parser_action;
429
430
431 #ifndef NULL_VALUE_INITIALIZER
432 #define NULL_VALUE_INITIALIZER = { 0 }
433 #endif
434
435 static parse_vs_type const ag_null_value NULL_VALUE_INITIALIZER;
436
437 static const unsigned char ag_rpx[] = {
438 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 6, 7,
439 8, 9, 10, 0, 11, 12, 13, 14, 15, 16, 17, 18, 0, 19, 20, 0, 21, 22,
440 23, 24, 25, 0, 26, 27, 0, 28, 29, 0, 30, 0, 31, 32, 33, 34, 35
441 };
442
443 static const unsigned char ag_key_itt[] = {
444 0
445 };
446
447 static const unsigned short ag_key_pt[] = {
448 0
449 };
450
451 static const unsigned char ag_key_ch[] = {
452 0, 47, 68, 80, 81, 86,255, 47, 61, 67, 68, 80, 81, 86,255, 68, 80, 81,
453 86,255, 42,255, 47, 67, 86,255, 47,255, 47, 61,255, 61,255, 47, 67,255,
454 67,255, 47, 61, 67, 86,255, 67, 86,255
455 };
456
457 static const unsigned char ag_key_act[] = {
458 0,3,3,3,3,3,4,3,3,3,3,3,3,3,4,3,3,3,3,4,3,4,3,3,3,4,3,4,3,3,4,3,4,3,3,
459 4,3,4,3,3,3,3,4,3,3,4
460 };
461
462 static const unsigned char ag_key_parm[] = {
463 0, 46, 59, 60, 62, 61, 0, 46, 68, 65, 59, 60, 62, 61, 0, 59, 60, 62,
464 61, 0, 49, 0, 46, 65, 61, 0, 46, 0, 46, 68, 0, 68, 0, 46, 65, 0,
465 65, 0, 46, 68, 65, 61, 0, 65, 61, 0
466 };
467
468 static const unsigned char ag_key_jmp[] = {
469 0, 0, 2, 8, 13, 17, 0, 20, 22, 24, 29, 35, 40, 44, 0, 47, 53, 58,
470 62, 0, 65, 0, 67, 69, 74, 0, 77, 0, 79, 81, 0, 83, 0, 85, 87, 0,
471 92, 0, 97, 99,101,106, 0,109,114, 0
472 };
473
474 static const unsigned char ag_key_index[] = {
475 1, 0, 7, 15, 20, 22, 26, 0, 28, 0, 28, 31, 31, 31, 31, 31, 26, 33,
476 26, 26, 31, 36, 0, 0, 0, 15, 31, 0, 31, 26, 0, 0, 26, 0, 26, 0,
477 26, 0, 0, 26, 0, 26, 0, 26, 0, 26, 0, 26, 0, 0, 1, 26, 0, 38,
478 0, 0, 31, 31, 31, 0, 0, 0, 43, 22, 0, 0, 43, 0, 0, 0, 0, 43,
479 0, 43, 0, 0, 0
480 };
481
482 static const unsigned char ag_key_ends[] = {
483 42,0, 69,70,73,78,69,0, 82,73,78,84,0, 85,73,84,0, 65,82,0,
484 42,0, 61,0, 79,78,83,84,0, 69,70,73,78,69,0, 82,73,78,84,0,
485 85,73,84,0, 65,82,0, 69,70,73,78,69,0, 82,73,78,84,0, 85,73,84,0,
486 65,82,0, 47,0, 42,0, 79,78,83,84,0, 65,82,0, 42,0, 42,0, 61,0,
487 61,0, 42,0, 79,78,83,84,0, 79,78,83,84,0, 42,0, 61,0,
488 79,78,83,84,0, 65,82,0, 79,78,83,84,0, 65,82,0,
489 };
490 #define AG_TCV(x) (((int)(x) >= 0 && (int)(x) <= 308) ? ag_tcv[(x)] : 0)
491
492 static const unsigned char ag_tcv[] = {
493 54, 50, 50, 50, 50, 50, 50, 50, 50, 44, 51, 50, 50, 51, 50, 50, 50, 50,
494 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 44, 50, 50, 50,
495 50, 50, 50, 50, 57, 56, 71, 69, 63, 70, 50, 72, 50, 50, 50, 50, 50, 50,
496 50, 50, 50, 50, 50, 55, 67, 64, 66, 50, 50, 50, 50, 50, 50, 50, 50, 50,
497 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
498 50, 50, 50, 50, 73, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
499 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
500 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
501 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
502 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
503 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
504 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
505 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
506 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
507 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
508 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
509 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
510 50, 50, 50
511 };
512
513 #ifndef SYNTAX_ERROR
514 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
515 (PCB).error_message, (PCB).line, (PCB).column)
516 #endif
517
518 #ifndef FIRST_LINE
519 #define FIRST_LINE 1
520 #endif
521
522 #ifndef FIRST_COLUMN
523 #define FIRST_COLUMN 1
524 #endif
525
526 #ifndef PARSER_STACK_OVERFLOW
527 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \
528 "\nParser stack overflow, line %d, column %d\n",\
529 (PCB).line, (PCB).column);}
530 #endif
531
532 #ifndef REDUCTION_TOKEN_ERROR
533 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
534 "\nReduction token error, line %d, column %d\n", \
535 (PCB).line, (PCB).column);}
536 #endif
537
538
539 typedef enum
540 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
541 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
542
543 #ifndef GET_INPUT
544 #define GET_INPUT ((PCB).input_code = getchar())
545 #endif
546
547
548 static int ag_look_ahead(void) {
549 if ((PCB).rx < (PCB).fx) {
550 return CONVERT_CASE((PCB).lab[(PCB).rx++]);
551 }
552 GET_INPUT;
553 (PCB).fx++;
554 return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code);
555 }
556
557 static void ag_get_key_word(int ag_k) {
558 int save_index = (PCB).rx;
559 const unsigned char *sp;
560 int ag_ch;
561 while (1) {
562 switch (ag_key_act[ag_k]) {
563 case ag_cf_end_key:
564 sp = ag_key_ends + ag_key_jmp[ag_k];
565 do {
566 if ((ag_ch = *sp++) == 0) {
567 int ag_k1 = ag_key_parm[ag_k];
568 int ag_k2 = ag_key_pt[ag_k1];
569 if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail;
570 (PCB).rx--;
571 (PCB).token_number = (parse_token_type) ag_key_pt[ag_k1 + 1];
572 return;
573 }
574 } while (ag_look_ahead() == ag_ch);
575 goto ag_fail;
576 case ag_end_key:
577 sp = ag_key_ends + ag_key_jmp[ag_k];
578 do {
579 if ((ag_ch = *sp++) == 0) {
580 (PCB).token_number = (parse_token_type) ag_key_parm[ag_k];
581 return;
582 }
583 } while (ag_look_ahead() == ag_ch);
584 case ag_no_match_key:
585 ag_fail:
586 (PCB).rx = save_index;
587 return;
588 case ag_cf_set_key: {
589 int ag_k1 = ag_key_parm[ag_k];
590 int ag_k2 = ag_key_pt[ag_k1];
591 ag_k = ag_key_jmp[ag_k];
592 if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break;
593 save_index = --(PCB).rx;
594 (PCB).token_number = (parse_token_type) ag_key_pt[ag_k1+1];
595 break;
596 }
597 case ag_set_key:
598 save_index = (PCB).rx;
599 (PCB).token_number = (parse_token_type) ag_key_parm[ag_k];
600 case ag_jmp_key:
601 ag_k = ag_key_jmp[ag_k];
602 ag_ch = ag_look_ahead();
603 break;
604 case ag_accept_key:
605 (PCB).token_number = (parse_token_type) ag_key_parm[ag_k];
606 return;
607 case ag_cf_accept_key: {
608 int ag_k1 = ag_key_parm[ag_k];
609 int ag_k2 = ag_key_pt[ag_k1];
610 if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index;
611 else {
612 (PCB).rx--;
613 (PCB).token_number = (parse_token_type) ag_key_pt[ag_k1+1];
614 }
615 return;
616 }
617 default:
618 /* not reachable; here to suppress compiler warnings */
619 goto ag_fail;
620 }
621 if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++;
622 if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) {
623 (PCB).rx = save_index;
624 return;
625 }
626 }
627 }
628
629
630 #ifndef AG_NEWLINE
631 #define AG_NEWLINE 10
632 #endif
633
634 #ifndef AG_RETURN
635 #define AG_RETURN 13
636 #endif
637
638 #ifndef AG_FORMFEED
639 #define AG_FORMFEED 12
640 #endif
641
642 #ifndef AG_TABCHAR
643 #define AG_TABCHAR 9
644 #endif
645
646 static void ag_track(void) {
647 int ag_k = 0;
648 while (ag_k < (PCB).rx) {
649 int ag_ch = (PCB).lab[ag_k++];
650 switch (ag_ch) {
651 case AG_NEWLINE:
652 (PCB).column = 1, (PCB).line++;
653 case AG_RETURN:
654 case AG_FORMFEED:
655 break;
656 case AG_TABCHAR:
657 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
658 break;
659 default:
660 (PCB).column++;
661 }
662 }
663 ag_k = 0;
664 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++];
665 (PCB).fx = ag_k;
666 (PCB).rx = 0;
667 }
668
669
670 static void ag_prot(void) {
671 int ag_k;
672 ag_k = 1000 - ++(PCB).btsx;
673 if (ag_k <= (PCB).ssx) {
674 (PCB).exit_flag = AG_STACK_ERROR_CODE;
675 PARSER_STACK_OVERFLOW;
676 return;
677 }
678 (PCB).bts[(PCB).btsx] = (PCB).sn;
679 (PCB).bts[ag_k] = (PCB).ssx;
680 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
681 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
682 }
683
684 static void ag_undo(void) {
685 if ((PCB).drt == -1) return;
686 while ((PCB).btsx) {
687 int ag_k = 1000 - (PCB).btsx;
688 (PCB).sn = (PCB).bts[(PCB).btsx--];
689 (PCB).ssx = (PCB).bts[ag_k];
690 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
691 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
692 }
693 (PCB).token_number = (parse_token_type) (PCB).drt;
694 (PCB).ssx = (PCB).dssx;
695 (PCB).sn = (PCB).dsn;
696 (PCB).drt = -1;
697 }
698
699
700 static const unsigned char ag_tstt[] = {
701 73,70,62,61,60,59,57,51,50,46,44,0,1,52,53,
702 73,72,71,70,69,67,66,64,63,57,56,55,51,50,44,0,48,
703 51,46,44,0,1,
704 73,70,62,61,60,59,57,50,0,2,3,4,5,6,8,10,11,15,16,18,19,27,28,32,33,35,37,
705 38,40,58,
706 73,72,71,70,69,67,66,64,63,57,56,55,51,50,49,44,0,
707 73,70,65,63,61,57,56,51,50,46,44,0,1,52,53,
708 73,70,57,51,50,46,44,0,1,52,53,
709 73,70,57,50,0,2,3,11,14,19,20,27,28,32,33,35,37,38,40,58,
710 73,50,44,0,
711 73,70,57,50,0,2,3,11,27,33,37,38,40,58,
712 73,72,71,70,69,68,67,66,64,63,57,56,55,51,50,46,44,0,1,52,53,
713 73,0,42,
714 57,0,11,
715 72,71,0,39,41,
716 64,0,26,
717 70,69,0,36,37,
718 55,51,46,44,0,1,52,53,
719 73,65,51,50,46,44,0,1,52,53,
720 73,51,50,46,44,0,1,52,53,
721 73,51,50,46,44,0,1,52,53,
722 68,67,66,0,29,30,31,
723 73,65,50,0,2,3,17,25,58,
724 73,50,0,2,3,58,
725 73,50,0,2,3,58,
726 55,0,9,
727 73,70,62,61,60,59,57,54,50,0,2,3,5,7,8,10,11,15,16,18,19,27,28,32,33,35,37,
728 38,40,58,
729 68,67,66,55,0,9,29,30,31,
730 56,0,13,
731 73,0,42,
732 73,57,51,50,46,44,0,1,52,53,
733 73,57,50,0,2,3,11,27,33,40,58,
734 73,70,57,56,50,0,2,3,11,14,19,20,27,28,32,33,34,35,37,38,40,58,
735 73,57,51,50,46,44,0,1,52,53,
736 73,57,50,0,2,3,11,27,33,40,58,
737 73,57,51,50,46,44,0,1,52,53,
738 73,57,50,0,2,3,11,27,33,40,58,
739 73,70,57,51,50,46,44,0,1,52,53,
740 73,70,57,50,0,2,3,11,27,32,33,35,37,38,40,58,
741 73,70,57,50,0,2,3,11,27,33,35,37,38,40,58,
742 73,70,57,51,50,46,44,0,1,52,53,
743 73,70,57,50,0,2,3,11,27,33,35,37,38,40,58,
744 73,70,57,51,50,46,44,0,1,52,53,
745 73,70,57,50,0,2,3,11,27,28,32,33,35,37,38,40,58,
746 73,70,64,57,51,50,46,44,0,1,52,53,
747 73,70,64,57,50,0,2,3,11,26,27,28,32,33,35,37,38,40,58,
748 73,70,64,57,51,50,46,44,0,1,52,53,
749 73,70,64,57,50,0,2,3,11,26,27,28,32,33,35,37,38,40,58,
750 73,51,50,46,44,0,1,52,53,
751 73,50,0,2,3,58,
752 57,0,11,
753 73,70,63,62,61,60,59,57,56,54,51,50,46,44,0,1,52,53,
754 51,46,44,0,1,52,53,
755 73,70,57,50,0,2,3,11,19,20,27,28,32,33,35,37,38,40,58,
756 73,72,71,70,69,68,67,66,65,63,61,57,56,55,51,50,46,44,0,1,52,53,
757 63,0,24,
758 56,0,13,
759 70,69,0,36,37,
760 72,71,0,39,41,
761 72,71,0,39,41,
762 73,70,57,50,0,2,3,11,27,28,32,33,35,37,38,40,58,
763 73,70,57,50,0,2,3,11,27,28,32,33,35,37,38,40,58,
764 64,0,26,
765 73,65,63,61,56,50,0,12,21,
766 73,70,65,61,57,56,51,50,46,44,0,1,52,53,
767 73,70,57,56,50,0,2,3,11,14,19,20,27,28,32,33,34,35,37,38,40,58,
768 73,50,0,2,3,27,58,
769 73,65,63,61,57,56,50,0,2,3,16,22,23,25,58,
770 56,0,13,
771 73,50,0,2,3,58,
772 73,50,0,2,3,58,
773 63,0,24,
774 73,65,63,61,57,50,0,12,21,
775 73,50,0,2,3,27,58,
776 73,65,61,50,0,2,3,16,23,25,58,
777 57,0,11,
778 73,70,57,50,0,2,3,11,14,19,20,27,28,32,33,35,37,38,40,58,
779 56,0,13,
780
781 };
782
783
784 static unsigned const char ag_astt[823] = {
785 8,8,8,8,8,8,8,1,8,1,1,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,7,1,9,1,9,5,3,
786 2,1,1,1,1,1,1,2,7,1,1,0,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,
787 9,9,9,9,9,9,9,3,9,7,5,5,5,5,5,5,5,1,5,1,1,7,1,1,3,5,5,5,1,5,1,1,7,1,1,3,2,
788 1,1,2,7,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,10,10,10,4,2,1,1,2,7,1,1,1,2,1,1,1,1,
789 1,5,5,5,5,5,5,5,5,5,5,5,5,5,1,5,1,1,7,1,1,3,1,5,1,1,4,1,1,1,5,1,1,1,4,1,1,
790 1,5,1,1,5,1,1,1,7,1,1,3,5,5,1,5,1,1,7,1,1,3,5,1,5,1,1,7,1,1,3,5,1,5,1,1,7,
791 1,1,3,1,1,1,4,1,1,1,2,1,2,7,2,1,3,1,1,2,2,7,3,1,1,2,2,7,1,1,1,1,7,3,2,1,1,
792 1,1,1,1,1,2,7,1,1,3,3,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,
793 7,3,1,4,1,5,5,1,5,1,1,7,1,1,3,2,1,2,7,1,1,1,2,2,2,1,2,1,1,4,2,7,1,1,1,1,1,
794 2,1,1,1,1,1,1,1,1,1,1,5,5,1,5,1,1,7,1,1,3,2,1,2,7,1,1,1,2,2,2,1,5,5,1,5,1,
795 1,7,1,1,3,2,1,2,7,1,1,1,2,2,2,1,5,5,5,1,5,1,1,7,1,1,3,2,1,1,2,7,1,1,1,2,1,
796 1,1,1,1,1,1,2,1,1,2,7,1,1,1,2,1,1,1,1,1,1,5,5,5,1,5,1,1,7,1,1,3,2,1,1,2,7,
797 1,1,1,2,1,1,1,1,1,1,5,5,5,1,5,1,1,7,1,1,3,2,1,1,2,7,1,1,1,1,2,1,1,1,1,1,1,
798 1,5,5,5,5,1,5,1,1,7,1,1,3,2,1,1,1,2,7,1,1,1,1,1,2,1,1,1,1,1,1,1,5,5,5,5,1,
799 5,1,1,7,1,1,3,2,1,1,1,2,7,1,1,1,1,1,2,1,1,1,1,1,1,1,5,1,5,1,1,7,1,1,3,2,2,
800 7,1,1,1,1,7,1,5,5,5,5,5,5,5,5,5,5,1,5,1,1,7,1,1,3,1,1,1,5,1,1,3,2,1,1,2,4,
801 1,1,1,1,2,1,1,1,1,1,1,1,1,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,5,1,1,7,1,1,3,1,
802 4,1,1,7,2,1,1,4,1,1,1,1,4,1,1,1,1,4,1,1,2,1,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,
803 2,1,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,1,7,1,4,4,4,4,4,4,7,1,1,5,5,5,5,5,5,1,5,
804 1,1,7,1,1,3,2,1,1,4,2,7,1,1,1,1,1,2,1,1,1,1,2,1,1,1,1,1,2,2,7,2,1,2,1,2,1,
805 8,1,5,5,2,7,2,1,1,1,1,1,1,1,7,1,2,2,7,1,1,1,2,2,7,2,1,1,1,4,1,4,4,4,4,4,4,
806 7,1,1,2,2,7,2,1,2,1,2,1,1,2,7,2,1,1,3,1,1,1,7,1,2,1,1,2,7,1,1,1,1,1,2,1,1,
807 1,1,1,1,1,1,1,1,7,3
808 };
809
810
811 static const unsigned char ag_pstt[] = {
812 3,3,3,3,3,3,3,2,3,1,2,0,2,2,3,
813 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,4,
814 77,1,77,79,77,
815 50,6,16,17,18,19,5,50,3,12,8,0,25,25,24,23,7,22,21,8,20,14,20,15,11,13,9,11,
816 11,10,
817 55,55,55,55,55,55,55,55,55,55,55,55,55,55,56,55,4,
818 78,78,78,78,78,78,78,2,78,1,2,5,2,2,83,
819 78,78,78,2,78,1,2,6,2,2,96,
820 50,6,5,50,7,12,8,7,27,26,10,14,26,15,11,13,9,11,11,10,
821 51,51,52,49,
822 50,6,5,50,9,12,8,7,46,28,9,28,28,10,
823 78,78,78,78,78,78,78,78,78,78,78,78,78,2,78,1,2,10,2,2,84,
824 29,39,30,
825 5,48,31,
826 32,34,33,35,33,
827 36,46,37,
828 6,39,30,40,38,
829 78,2,1,2,16,2,2,88,
830 78,78,2,78,1,2,17,2,2,87,
831 78,2,78,1,2,18,2,2,86,
832 78,2,78,1,2,19,2,2,85,
833 41,43,45,9,46,44,42,
834 50,47,50,21,16,8,7,48,10,
835 50,50,22,6,8,10,
836 50,50,23,49,8,10,
837 50,24,4,
838 50,6,16,17,18,19,5,51,50,25,12,8,2,3,24,23,7,22,21,8,20,14,20,15,11,13,9,11,
839 11,10,
840 41,43,45,50,27,52,46,44,42,
841 53,27,45,
842 29,43,30,
843 78,78,2,78,1,2,29,2,2,99,
844 50,5,50,30,12,8,7,46,44,44,10,
845 50,6,5,36,50,31,12,8,7,54,26,10,14,26,15,11,55,13,9,11,11,10,
846 78,78,2,78,1,2,32,2,2,98,
847 50,5,50,33,12,8,7,46,41,41,10,
848 78,78,2,78,1,2,34,2,2,97,
849 50,5,50,35,12,8,7,46,40,40,10,
850 78,78,78,2,78,1,2,36,2,2,90,
851 50,6,5,50,37,12,8,7,46,56,11,13,9,11,11,10,
852 50,6,5,50,38,12,8,7,46,11,57,9,11,11,10,
853 78,78,78,2,78,1,2,39,2,2,95,
854 50,6,5,50,40,12,8,7,46,11,58,9,11,11,10,
855 78,78,78,2,78,1,2,41,2,2,94,
856 50,6,5,50,42,12,8,7,14,24,15,11,13,9,11,11,10,
857 78,78,78,78,2,78,1,2,43,2,2,93,
858 50,6,36,5,50,44,12,8,7,59,14,23,15,11,13,9,11,11,10,
859 78,78,78,78,2,78,1,2,45,2,2,92,
860 50,6,36,5,50,46,12,8,7,60,14,22,15,11,13,9,11,11,10,
861 78,2,78,1,2,47,2,2,91,
862 50,50,48,61,8,10,
863 5,49,62,
864 78,78,78,78,78,78,78,78,78,78,2,78,1,2,50,2,2,81,
865 2,1,2,78,2,2,80,
866 50,6,5,50,28,12,8,7,26,29,14,26,15,11,13,9,11,11,10,
867 78,78,78,78,78,78,78,78,78,78,78,78,78,78,2,78,1,2,53,2,2,82,
868 63,37,64,
869 53,55,32,
870 6,39,31,40,38,
871 32,34,35,35,33,
872 32,34,34,35,33,
873 50,6,5,50,59,12,8,7,14,26,15,11,13,9,11,11,10,
874 50,6,5,50,60,12,8,7,14,25,15,11,13,9,11,11,10,
875 36,61,65,
876 11,11,11,11,11,11,62,67,66,
877 78,78,78,78,78,78,2,78,1,2,63,2,2,89,
878 50,6,5,36,50,64,12,8,7,54,26,10,14,26,15,11,38,13,9,11,11,10,
879 50,50,65,48,8,17,10,
880 50,47,70,17,13,13,50,66,18,8,69,70,70,68,10,
881 53,67,71,
882 50,50,68,72,8,10,
883 50,50,69,19,8,10,
884 63,12,73,
885 11,11,11,11,11,11,71,74,66,
886 50,50,72,48,8,20,10,
887 50,47,17,50,73,18,8,69,15,68,10,
888 5,74,75,
889 50,6,5,50,75,12,8,7,76,26,10,14,26,15,11,13,9,11,11,10,
890 53,76,5,
891
892 };
893
894
895 static const unsigned short ag_sbt[] = {
896 0, 15, 32, 37, 67, 84, 99, 110, 130, 134, 148, 169, 172, 175,
897 180, 183, 188, 196, 206, 215, 224, 231, 240, 246, 252, 255, 285, 294,
898 297, 300, 310, 321, 343, 353, 364, 374, 385, 396, 412, 427, 438, 453,
899 464, 481, 493, 512, 524, 543, 552, 558, 561, 579, 586, 605, 627, 630,
900 633, 638, 643, 648, 665, 682, 685, 694, 708, 730, 737, 752, 755, 761,
901 767, 770, 779, 786, 797, 800, 820, 823
902 };
903
904
905 static const unsigned short ag_sbe[] = {
906 11, 30, 35, 45, 83, 95, 106, 114, 133, 138, 165, 170, 173, 177,
907 181, 185, 192, 202, 211, 220, 227, 234, 242, 248, 253, 264, 289, 295,
908 298, 306, 313, 326, 349, 356, 370, 377, 392, 400, 416, 434, 442, 460,
909 468, 489, 498, 520, 529, 548, 554, 559, 575, 582, 590, 623, 628, 631,
910 635, 640, 645, 652, 669, 683, 691, 704, 713, 732, 744, 753, 757, 763,
911 768, 776, 781, 790, 798, 804, 821, 823
912 };
913
914
915 static const unsigned char ag_fl[] = {
916 2,1,2,2,2,9,2,2,1,1,1,0,2,0,1,3,1,4,1,2,3,1,3,3,3,4,4,1,2,3,1,3,4,1,3,
917 3,0,1,3,1,3,3,1,2,3,3,1,1,1,1,1,2,2,1,1,2,3,1,1,1,1,1,1,1,1,1,1,1,1,1,
918 1,1,1,1,1,1,1,2,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
919 };
920
921 static const unsigned char ag_ptt[] = {
922 0, 6, 6, 4, 5, 8, 8, 8, 8, 8, 14, 21, 12, 22, 22, 22, 17, 17,
923 23, 23, 23, 19, 19, 19, 19, 19, 19, 20, 20, 20, 28, 28, 33, 32, 32, 32,
924 34, 34, 34, 35, 35, 35, 38, 38, 38, 40, 40, 40, 27, 58, 3, 3, 3, 1,
925 48, 48, 1, 43, 43, 45, 45, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
926 47, 47, 47, 47, 52, 52, 53, 53, 7, 9, 13, 11, 2, 10, 15, 16, 18, 24,
927 26, 25, 29, 30, 31, 36, 37, 39, 41, 42
928 };
929
930
931 static void ag_ra(void)
932 {
933 switch(ag_rpx[(PCB).ag_ap]) {
934 case 1: ag_rp_1(); break;
935 case 2: ag_rp_2(); break;
936 case 3: ag_rp_3(V(0,(int *))); break;
937 case 4: ag_rp_4(); break;
938 case 5: V(0,(struct LocaleNode * *)) = ag_rp_5(); break;
939 case 6: ag_rp_6(V(0,(struct String * *))); break;
940 case 7: ag_rp_7(V(1,(struct String * *)), V(3,(Object * *))); break;
941 case 8: ag_rp_8(V(0,(struct String * *))); break;
942 case 9: ag_rp_9(V(1,(struct String * *))); break;
943 case 10: ag_rp_10(V(1,(struct String * *)), V(2,(Object * *))); break;
944 case 11: ag_rp_11(); break;
945 case 12: ag_rp_12(); break;
946 case 13: ag_rp_13(); break;
947 case 14: ag_rp_14(); break;
948 case 15: ag_rp_15(); break;
949 case 16: V(0,(int *)) = ag_rp_16(); break;
950 case 17: V(0,(int *)) = ag_rp_17(); break;
951 case 18: V(0,(int *)) = ag_rp_18(V(2,(int *))); break;
952 case 19: ag_rp_19(V(0,(Object * *))); break;
953 case 20: ag_rp_20(V(0,(struct String * *)), V(2,(unsigned *))); break;
954 case 21: ag_rp_21(); break;
955 case 22: ag_rp_22(); break;
956 case 23: V(0,(unsigned *)) = ag_rp_23(); break;
957 case 24: V(0,(unsigned *)) = ag_rp_24(); break;
958 case 25: V(0,(unsigned *)) = ag_rp_25(V(2,(unsigned *))); break;
959 case 26: ag_rp_26(); break;
960 case 27: ag_rp_27(); break;
961 case 28: ag_rp_28(); break;
962 case 29: ag_rp_29(); break;
963 case 30: ag_rp_30(V(0,(Object * *))); break;
964 case 31: V(0,(Object * *)) = ag_rp_31(V(0,(struct String * *))); break;
965 case 32: V(0,(struct String * *)) = ag_rp_32(V(0,(struct String * *))); break;
966 case 33: V(0,(struct String * *)) = ag_rp_33(V(0,(int *))); break;
967 case 34: V(0,(struct String * *)) = ag_rp_34(V(0,(struct String * *)), V(1,(int *))); break;
968 case 35: V(0,(struct String * *)) = ag_rp_35(V(0,(struct String * *)), V(1,(int *))); break;
969 }
970 }
971
972 #define TOKEN_NAMES parse_token_names
973 const char *const parse_token_names[74] = {
974 "LineParse",
975 "WhiteSpace",
976 "VariNumStr",
977 "StringBody",
978 "LineParse",
979 "Terminated Line",
980 "",
981 "",
982 "Line",
983 "';'",
984 "\"DEFINE\"",
985 "'('",
986 "VariableList",
987 "')'",
988 "Group",
989 "\"PRINT\"",
990 "\"VAR\"",
991 "VariableDecl",
992 "\"QUIT\"",
993 "Comparison",
994 "Comparisons",
995 "",
996 "VariableListWork",
997 "VariListMemb",
998 "','",
999 "\"CONST\"",
1000 "'='",
1001 "VariNum",
1002 "Assignment",
1003 "'>'",
1004 "'<'",
1005 "\"==\"",
1006 "Expression",
1007 "FunctionCall",
1008 "ArgumentList",
1009 "Product",
1010 "'+'",
1011 "'-'",
1012 "PowerFactor",
1013 "'*'",
1014 "Factor",
1015 "'/'",
1016 "'^'",
1017 "ALNUM",
1018 "WS",
1019 "WSDISREGARD",
1020 "\"/*\"",
1021 "ANYTHING",
1022 "",
1023 "\"*/\"",
1024 "",
1025 "",
1026 "",
1027 "",
1028 "",
1029 "';'",
1030 "')'",
1031 "'('",
1032 "VariNumStr",
1033 "\"DEFINE\"",
1034 "\"PRINT\"",
1035 "\"VAR\"",
1036 "\"QUIT\"",
1037 "','",
1038 "'='",
1039 "\"CONST\"",
1040 "'>'",
1041 "'<'",
1042 "\"==\"",
1043 "'+'",
1044 "'-'",
1045 "'*'",
1046 "'/'",
1047 "'^'",
1048
1049 };
1050
1051 #ifndef MISSING_FORMAT
1052 #define MISSING_FORMAT "Missing %s"
1053 #endif
1054 #ifndef UNEXPECTED_FORMAT
1055 #define UNEXPECTED_FORMAT "Unexpected %s"
1056 #endif
1057 #ifndef UNNAMED_TOKEN
1058 #define UNNAMED_TOKEN "input"
1059 #endif
1060
1061
1062 static void ag_diagnose(void) {
1063 int ag_snd = (PCB).sn;
1064 int ag_k = ag_sbt[ag_snd];
1065
1066 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) {
1067 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
1068 }
1069 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8
1070 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1
1071 && *TOKEN_NAMES[ag_tstt[ag_k]]) {
1072 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]);
1073 }
1074 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
1075 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]);
1076 }
1077 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') {
1078 char buf[20];
1079 sprintf(buf, "\'%c\'", (char) (*(PCB).lab));
1080 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf);
1081 }
1082 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN);
1083 (PCB).error_message = (PCB).ag_msg;
1084
1085
1086 }
1087 static int ag_action_1_r_proc(void);
1088 static int ag_action_2_r_proc(void);
1089 static int ag_action_3_r_proc(void);
1090 static int ag_action_4_r_proc(void);
1091 static int ag_action_1_s_proc(void);
1092 static int ag_action_3_s_proc(void);
1093 static int ag_action_1_proc(void);
1094 static int ag_action_2_proc(void);
1095 static int ag_action_3_proc(void);
1096 static int ag_action_4_proc(void);
1097 static int ag_action_5_proc(void);
1098 static int ag_action_6_proc(void);
1099 static int ag_action_7_proc(void);
1100 static int ag_action_8_proc(void);
1101 static int ag_action_9_proc(void);
1102 static int ag_action_10_proc(void);
1103 static int ag_action_11_proc(void);
1104 static int ag_action_8_proc(void);
1105
1106
1107 static int (*const ag_r_procs_scan[])(void) = {
1108 ag_action_1_r_proc,
1109 ag_action_2_r_proc,
1110 ag_action_3_r_proc,
1111 ag_action_4_r_proc
1112 };
1113
1114 static int (*const ag_s_procs_scan[])(void) = {
1115 ag_action_1_s_proc,
1116 ag_action_2_r_proc,
1117 ag_action_3_s_proc,
1118 ag_action_4_r_proc
1119 };
1120
1121 static int (*const ag_gt_procs_scan[])(void) = {
1122 ag_action_1_proc,
1123 ag_action_2_proc,
1124 ag_action_3_proc,
1125 ag_action_4_proc,
1126 ag_action_5_proc,
1127 ag_action_6_proc,
1128 ag_action_7_proc,
1129 ag_action_8_proc,
1130 ag_action_9_proc,
1131 ag_action_10_proc,
1132 ag_action_11_proc,
1133 ag_action_8_proc
1134 };
1135
1136
1137 static int ag_action_10_proc(void) {
1138 int ag_t = (PCB).token_number;
1139 (PCB).btsx = 0, (PCB).drt = -1;
1140 do {
1141 ag_track();
1142 if ((PCB).rx < (PCB).fx) {
1143 (PCB).input_code = (PCB).lab[(PCB).rx++];
1144 (PCB).token_number = (parse_token_type) AG_TCV((PCB).input_code);}
1145 else {
1146 GET_INPUT;
1147 (PCB).lab[(PCB).fx++] = (PCB).input_code;
1148 (PCB).token_number = (parse_token_type) AG_TCV((PCB).input_code);
1149 (PCB).rx++;
1150 }
1151 if (ag_key_index[(PCB).sn]) {
1152 unsigned ag_k = ag_key_index[(PCB).sn];
1153 int ag_ch = CONVERT_CASE((PCB).input_code);
1154 if (ag_ch < 255) {
1155 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1156 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
1157 }
1158 }
1159 } while ((PCB).token_number == (parse_token_type) ag_t);
1160 (PCB).rx = 0;
1161 return 1;
1162 }
1163
1164 static int ag_action_11_proc(void) {
1165 int ag_t = (PCB).token_number;
1166
1167 (PCB).btsx = 0, (PCB).drt = -1;
1168 do {
1169 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1170 (PCB).ssx--;
1171 ag_track();
1172 ag_ra();
1173 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
1174 (PCB).ssx++;
1175 if ((PCB).rx < (PCB).fx) {
1176 (PCB).input_code = (PCB).lab[(PCB).rx++];
1177 (PCB).token_number = (parse_token_type) AG_TCV((PCB).input_code);}
1178 else {
1179 GET_INPUT;
1180 (PCB).lab[(PCB).fx++] = (PCB).input_code;
1181 (PCB).token_number = (parse_token_type) AG_TCV((PCB).input_code);
1182 (PCB).rx++;
1183 }
1184 if (ag_key_index[(PCB).sn]) {
1185 unsigned ag_k = ag_key_index[(PCB).sn];
1186 int ag_ch = CONVERT_CASE((PCB).input_code);
1187 if (ag_ch < 255) {
1188 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1189 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
1190 }
1191 }
1192 }
1193 while ((PCB).token_number == (parse_token_type) ag_t);
1194 (PCB).rx = 0;
1195 return 1;
1196 }
1197
1198 static int ag_action_3_r_proc(void) {
1199 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1200 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1201 (PCB).btsx = 0, (PCB).drt = -1;
1202 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1203 ag_ra();
1204 return (PCB).exit_flag == AG_RUNNING_CODE;
1205 }
1206
1207 static int ag_action_3_s_proc(void) {
1208 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1209 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1210 (PCB).btsx = 0, (PCB).drt = -1;
1211 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1212 ag_ra();
1213 return (PCB).exit_flag == AG_RUNNING_CODE;
1214 }
1215
1216 static int ag_action_4_r_proc(void) {
1217 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1218 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1219 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1220 return 1;
1221 }
1222
1223 static int ag_action_2_proc(void) {
1224 (PCB).btsx = 0, (PCB).drt = -1;
1225 if ((PCB).ssx >= 1000) {
1226 (PCB).exit_flag = AG_STACK_ERROR_CODE;
1227 PARSER_STACK_OVERFLOW;
1228 }
1229 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1230 (PCB).ss[(PCB).ssx] = (PCB).sn;
1231 (PCB).ssx++;
1232 (PCB).sn = (PCB).ag_ap;
1233 ag_track();
1234 return 0;
1235 }
1236
1237 static int ag_action_9_proc(void) {
1238 if ((PCB).drt == -1) {
1239 (PCB).drt=(PCB).token_number;
1240 (PCB).dssx=(PCB).ssx;
1241 (PCB).dsn=(PCB).sn;
1242 }
1243 ag_prot();
1244 (PCB).vs[(PCB).ssx] = ag_null_value;
1245 (PCB).ss[(PCB).ssx] = (PCB).sn;
1246 (PCB).ssx++;
1247 (PCB).sn = (PCB).ag_ap;
1248 (PCB).rx = 0;
1249 return (PCB).exit_flag == AG_RUNNING_CODE;
1250 }
1251
1252 static int ag_action_2_r_proc(void) {
1253 (PCB).ssx++;
1254 (PCB).sn = (PCB).ag_ap;
1255 return 0;
1256 }
1257
1258 static int ag_action_7_proc(void) {
1259 --(PCB).ssx;
1260 (PCB).rx = 0;
1261 (PCB).exit_flag = AG_SUCCESS_CODE;
1262 return 0;
1263 }
1264
1265 static int ag_action_1_proc(void) {
1266 ag_track();
1267 (PCB).exit_flag = AG_SUCCESS_CODE;
1268 return 0;
1269 }
1270
1271 static int ag_action_1_r_proc(void) {
1272 (PCB).exit_flag = AG_SUCCESS_CODE;
1273 return 0;
1274 }
1275
1276 static int ag_action_1_s_proc(void) {
1277 (PCB).exit_flag = AG_SUCCESS_CODE;
1278 return 0;
1279 }
1280
1281 static int ag_action_4_proc(void) {
1282 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1283 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1284 (PCB).btsx = 0, (PCB).drt = -1;
1285 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1286 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1287 else (PCB).ss[(PCB).ssx] = (PCB).sn;
1288 ag_track();
1289 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1290 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1291 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1292 do {
1293 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1294 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1295 else ag_t2 = ag_tx;
1296 } while (ag_t1 < ag_t2);
1297 (PCB).ag_ap = ag_pstt[ag_t1];
1298 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
1299 }
1300 return 0;
1301 }
1302
1303 static int ag_action_3_proc(void) {
1304 int ag_sd = ag_fl[(PCB).ag_ap] - 1;
1305 (PCB).btsx = 0, (PCB).drt = -1;
1306 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab;
1307 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1308 else (PCB).ss[(PCB).ssx] = (PCB).sn;
1309 ag_track();
1310 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1311 ag_ra();
1312 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1313 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1314 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1315 do {
1316 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1317 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1318 else ag_t2 = ag_tx;
1319 } while (ag_t1 < ag_t2);
1320 (PCB).ag_ap = ag_pstt[ag_t1];
1321 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
1322 }
1323 return 0;
1324 }
1325
1326 static int ag_action_8_proc(void) {
1327 ag_undo();
1328 (PCB).rx = 0;
1329 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
1330 ag_diagnose();
1331 SYNTAX_ERROR;
1332 {(PCB).rx = 1; ag_track();}
1333 return (PCB).exit_flag == AG_RUNNING_CODE;
1334 }
1335
1336 static int ag_action_5_proc(void) {
1337 int ag_sd = ag_fl[(PCB).ag_ap];
1338 (PCB).btsx = 0, (PCB).drt = -1;
1339 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1340 else {
1341 (PCB).ss[(PCB).ssx] = (PCB).sn;
1342 }
1343 (PCB).rx = 0;
1344 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1345 ag_ra();
1346 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1347 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1348 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1349 do {
1350 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1351 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1352 else ag_t2 = ag_tx;
1353 } while (ag_t1 < ag_t2);
1354 (PCB).ag_ap = ag_pstt[ag_t1];
1355 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
1356 }
1357 return (PCB).exit_flag == AG_RUNNING_CODE;
1358 }
1359
1360 static int ag_action_6_proc(void) {
1361 int ag_sd = ag_fl[(PCB).ag_ap];
1362 (PCB).reduction_token = (parse_token_type) ag_ptt[(PCB).ag_ap];
1363 if ((PCB).drt == -1) {
1364 (PCB).drt=(PCB).token_number;
1365 (PCB).dssx=(PCB).ssx;
1366 (PCB).dsn=(PCB).sn;
1367 }
1368 if (ag_sd) {
1369 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
1370 }
1371 else {
1372 ag_prot();
1373 (PCB).vs[(PCB).ssx] = ag_null_value;
1374 (PCB).ss[(PCB).ssx] = (PCB).sn;
1375 }
1376 (PCB).rx = 0;
1377 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1378 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
1379 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
1380 do {
1381 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1382 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
1383 else ag_t2 = ag_tx;
1384 } while (ag_t1 < ag_t2);
1385 (PCB).ag_ap = ag_pstt[ag_t1];
1386 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
1387 }
1388 return (PCB).exit_flag == AG_RUNNING_CODE;
1389 }
1390
1391
1392 void init_parse(void) {
1393 (PCB).rx = (PCB).fx = 0;
1394 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
1395 (PCB).exit_flag = AG_RUNNING_CODE;
1396 (PCB).line = FIRST_LINE;
1397 (PCB).column = FIRST_COLUMN;
1398 (PCB).btsx = 0, (PCB).drt = -1;
1399 }
1400
1401 void parse(void) {
1402 init_parse();
1403 (PCB).exit_flag = AG_RUNNING_CODE;
1404 while ((PCB).exit_flag == AG_RUNNING_CODE) {
1405 unsigned ag_t1 = ag_sbt[(PCB).sn];
1406 if (ag_tstt[ag_t1]) {
1407 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
1408 if ((PCB).rx < (PCB).fx) {
1409 (PCB).input_code = (PCB).lab[(PCB).rx++];
1410 (PCB).token_number = (parse_token_type) AG_TCV((PCB).input_code);}
1411 else {
1412 GET_INPUT;
1413 (PCB).lab[(PCB).fx++] = (PCB).input_code;
1414 (PCB).token_number = (parse_token_type) AG_TCV((PCB).input_code);
1415 (PCB).rx++;
1416 }
1417 if (ag_key_index[(PCB).sn]) {
1418 unsigned ag_k = ag_key_index[(PCB).sn];
1419 int ag_ch = CONVERT_CASE((PCB).input_code);
1420 if (ag_ch < 255) {
1421 while (ag_key_ch[ag_k] < ag_ch) ag_k++;
1422 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);
1423 }
1424 }
1425 do {
1426 unsigned ag_tx = (ag_t1 + ag_t2)/2;
1427 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number)
1428 ag_t1 = ag_tx + 1;
1429 else ag_t2 = ag_tx;
1430 } while (ag_t1 < ag_t2);
1431 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number)
1432 ag_t1 = ag_sbe[(PCB).sn];
1433 }
1434 (PCB).ag_ap = ag_pstt[ag_t1];
1435 (ag_gt_procs_scan[ag_astt[ag_t1]])();
1436 }
1437 }
1438
1439