comparison tests/agcl/oldagsrc/pgg24.syn @ 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 Syntax Analyzer.
3 Copyright (c) Jerome T. Holland, 1989, 1990, 1991, 1992
4 All Rights Reserved.
5 */
6
7 //#define INCLUDE_LOGGING
8
9 #include "assert.h" //ASSERT
10 #include "config.h"
11 #include "csexp.h"
12 #include "data.h" //DATA
13 #include "error.h"
14 #include "log.hpp"
15 #include "myalloc.h"
16 #include "rproc.h"
17 #include "stk.h" //STK
18 #include "symbol.h"
19 #include "token.h"
20 #include "tree.h"
21 #include "tsd.h"
22 #include "ut.h" //UT
23 #include <ctype.h> //CTYPE
24 #include <stdio.h> //STDIO
25 #include <stdlib.h> //STDLIB
26 #include <string.h> //STRING
27
28 #include "pgg24.h" //PGG
29
30 #undef MODULE
31 #define MODULE 3
32
33 }
34
35 [
36 auto resynch
37 context type = cint
38 default reductions
39 ~declare pcb
40 diagnose errors
41 lines and columns
42 error frame
43 line numbers
44 //~allow macros
45 nest comments
46 parser stack size = 128
47 pointer input
48 ~test range
49 token names
50 parser name = pgg
51 test file mask = "*.syn"
52
53 distinguish keywords {'.'}
54 parser file name = "#.cpp"
55 ]
56
57 any digit = digit + hex letter
58 anything = ~eof
59 backslash = '\\'
60 blank char = ' ' + tab
61 c literal elem = ~(single quote + double quote + eol chars + backslash + eof)
62 digit = '0-9'
63 double quote = '"'
64 eof = 0 + 26
65 eol chars = carriage return + newline
66 hex letter = 'a-f' + 'A-F'
67 letter = 'a-z' + 'A-Z' + '_'
68 newline = '\n'
69 nonoctal digit = any digit - octal digit
70 octal digit = '0-7'
71 carriage return= '\r'
72 simple c char = ~('{' + '}' + single quote + double quote + eof)
73 simple string char = ~eof - (any digit + double quote + backslash + eol chars)
74 single quote = '\''
75 tab = '\t'
76 vertical space = '\f' + '\v'
77
78 arrow
79 -> "->", blank?...
80
81 comma
82 -> ',', space?
83
84 ellipsis
85 -> "...", blank?...
86
87 equals
88 -> '=', space?
89
90 bang
91 -> '!', space?
92
93 left brace
94 -> '{', space?
95
96 left bracket
97 -> '[', space?
98
99 left parenthesis
100 -> '(', space?
101
102 minus
103 -> '-', space?
104
105 plus
106 -> '+', space?
107
108 right bracket
109 -> ']', blank?...
110
111 right brace
112 -> '}', blank?...
113
114 right parenthesis
115 -> ')', blank?...
116
117 right quote
118 -> single quote, blank?...
119
120 tilde
121 -> '~', space?
122
123 vertical bar
124 -> '|', space?
125
126 (void) syntax definition $
127 -> blank?..., end of line?, complete statements, statement?, eof
128
129 complete statements
130 -> production:t, end of line =production(t);
131 -> definition, end of line
132 -> embedded c, end of line =nPrologueSegments = 1;
133 -> configuration section, end of line
134 -> complete statements, complete statement
135
136 (void) complete statement
137 -> production:t, end of line =production(t);
138 -> simple statement, end of line
139
140 (void) statement
141 -> production:t =production(t);
142 -> simple statement
143
144 (int) production
145 -> left hand side:type =iws(),type;
146 -> left hand side, right hand side
147 -> production:type, end of line, right hand side =concat_list(),type;
148 -> production, end of line, additional rule spec...
149
150 (void) right hand side
151 -> arrow, rule specs
152
153 (void) simple statement
154 -> definition
155 -> embedded c
156 -> configuration section
157
158 (int) left hand side
159 -> token name list =0;
160 -> type definition:d, token name list =head_list_3(d);
161
162 (void) token name list //left hand side of productions
163 -> token name:x =sws(head_list_2(x));
164 -> token name list, comma, token name:x =aws(head_list_2(x));
165
166 (int) token name
167 -> name =0;
168 -> name, '$', blank?... =1;
169
170 (int) type definition
171 -> left parenthesis, data type, ')', space? =Cast::create();
172
173 (void) wrapper type
174 -> data type =Cast::create().requireWrapper();
175
176 (void) wrapper list
177 -> wrapper type
178 -> wrapper list, comma, wrapper type
179
180 (void) proper vp rule specs
181 -> vp rule spec:n =sws(n);
182 -> proper vp rule specs, additional vp rule spec
183
184 (void) additional vp rule spec
185 -> vertical bar, vp rule spec:n =aws(n);
186
187 (void) vp rule specs
188 -> reduction procedure:pn =sws((iws(),vp_form3(pn)));
189 -> vp rule specs, additional vp rule spec
190
191 (void) vp rules
192 -> vp rule specs | proper vp rule specs
193
194 (int) vp rule spec
195 -> grammar rule, reduction procedure:s =vp_form3(s);
196
197 (void) rule specs
198 -> reduction procedure:n =sws(form_spec_2(form1(),n));
199 -> rule spec:n =sws(n);
200 -> rule specs, additional rule spec
201
202 (void) additional rule spec
203 -> vertical bar, rule spec:n =aws(n);
204
205 (int) rule spec
206 -> grammar rule, reduction procedure:s =form_spec_2(makeRule(ruleElementStack.pop()),s);
207
208 (void) grammar rule
209 -> init grammar rule, rule element:e, parameter name:p =ruleElementStack.top().push(RuleElement(e,p));
210 -> grammar rule, comma,
211 rule element:e, parameter name:p =ruleElementStack.top().push(RuleElement(e,p));
212
213 init grammar rule
214 -> =ruleElementStack.push(AgStack<RuleElement>());
215
216 (int) reduction procedure
217 -> =0;
218 -> equals, embedded c =proc_spec_4(0);
219 -> equals, c expression, ';', blank?... =proc_spec_4(1);
220
221 (void) data type
222 -> type name
223 -> type name, template field
224 -> type name, template field?, abstract declarator =concat_string();
225
226 (void) type name
227 -> name
228 -> "::", !sss("::");, blank?..., name =concat_string();
229 -> type name, "::", !ass("::");, blank?..., name =concat_string();
230
231 (void) abstract declarator
232 -> indirect data type
233 -> direct abstract declarator
234 -> indirect data type, direct abstract declarator =concat_string();
235
236 (void) template field
237 -> template field head, data type, '>', blank?... =acs('>'), concat_string();
238
239 template field head
240 -> '<', blank?... = acs('<');
241 -> template field head, data type, ',', blank?... =acs(','), concat_string();
242
243 (void) direct abstract declarator
244 -> {left parenthesis =scs('(');}, abstract declarator,
245 right parenthesis =concat_string(), acs(')');
246
247 (void) star
248 -> '*', blank?... =sss(" *");
249
250 (void) pointer
251 -> star
252 -> star, name =concat_string();
253
254 (void) indirect data type
255 -> pointer
256 -> indirect data type, pointer =concat_string();
257
258 (void) name string
259 -> letter:c =scs(c);
260 -> name string, letter + digit :c =acs(c);
261 -> name string, blank..., letter + digit :c =acs(' '), acs(c);
262
263 (void) enum fix
264 -> "enum", blank..., letter + digit : c =sss("enum "), acs(c);
265 -> enum fix, letter + digit:c =acs(c);
266 -> enum fix, blank..., letter + digit:c =acs(' '), acs(c);
267
268 (void) name
269 -> name string, blank?...
270
271 (void) blank
272 -> blank char
273 -> c comment
274
275 (void) space
276 -> blank...
277 -> blank..., continuation
278 -> continuation
279
280 (void) continuation
281 -> comment, next line
282 -> next line
283
284 (void) next line
285 -> carriage return?, newline
286 -> carriage return?, newline, blank...
287
288 (void) white
289 -> blank
290 -> carriage return?, newline
291 -> comment, carriage return?, newline
292
293 (void) end of line
294 -> comment, carriage return?, newline
295 -> carriage return?, newline
296 -> end of line, white
297 -> end of line, vertical space //form feed
298
299 (void) comment
300 -> "//", ~eol chars & ~eof?...
301
302 (int) character
303 -> signed number
304 -> '^', 33..126:x, blank?... =x & 0x1f;
305
306 (int) quoted character
307 -> single quote, char const:c, right quote =(character_seen=1),c;
308
309 (int) signed number
310 -> sign:s, simple number:n, blank?... =s*n;
311
312 (int) sign
313 -> plus? =1;
314 -> minus =-1;
315
316 (int) simple number
317 -> decimal number
318 -> '0', octal number:n =n;
319 -> {"0x" | "0X"}, hex number:n =n;
320
321 (int) decimal number
322 -> '1-9':d =d - '0';
323 -> decimal number:n, '0-9':d =10*n + d - '0';
324
325 (int) octal number
326 -> =0;
327 -> octal number:n, '0-7':d =8*n + d - '0';
328
329 (int) hex number
330 -> hex digit:d =d;
331 -> hex number:n, hex digit:d =16*n + d;
332
333 (int) hex digit
334 -> '0-9':d =d-'0';
335 -> 'a-f' + 'A-F':d =(d&7)+9;
336
337 (int) rule element
338 -> token
339 -> mid rule action:p =vp_8a(p);
340
341 (int) token
342 -> union:n =form_element_1(n);
343 -> virtual production
344
345 (CharSetExpression *) union
346 -> intersection
347 -> union:u, plus, intersection:i =new CharSetUnion(u,i);
348 -> union:u, minus, intersection:i =new CharSetDifference(u,i);
349
350 (CharSetExpression *) intersection
351 -> negation
352 -> intersection:i, '&', space?, negation:n =new CharSetIntersection(i,n);
353
354 (CharSetExpression *) negation
355 -> simple set
356 -> tilde, negation:n =new CharSetComplement(n);
357
358 (int) char const
359 // -> anything -(single quote + backslash + eol chars):c =
360 // case_sensitive ? (c) : agToUpper((char) c);
361 -> anything -(single quote + backslash + eol chars)
362 -> escape sequence
363 -> octal escape
364 -> three octal
365 -> hex escape
366
367 (CharSetExpression *) simple set
368 -> character range
369 -> character:c =new IndividualCode(c);
370 -> quoted character:c =new IndividualChar(c);
371 -> name =ss2();
372 -> left parenthesis, union:x,
373 right parenthesis =x;
374
375 (CharSetExpression *) character range
376 -> single quote, char const:l, '-',
377 char const:r, right quote =(character_seen=1),new CharRange(l,r);
378 -> character:l, "..", space?, character:r =new CodeRange(l,r);
379
380 (void) definition
381 -> name, equals, union:n =definition_1(n);
382 -> name, equals, virtual production:p =definition_2(p);
383 -> name, equals, mid rule action:p =definition_2(vp_8a(p));
384
385 (void) enum definition
386 -> name =definition_3(enum_base++);
387 -> name, equals, character:n =definition_3(enum_base = n), enum_base++;
388 -> name, equals, quoted character:n =definition_3(enum_base = n), enum_base++;
389
390 (void) enum statement
391 -> "enum", space, left brace, enum definition
392 -> enum statement, comma, enum definition
393
394 (void) keyword string
395 -> keyword string head, string, double quote, blank?...
396
397 (void) string
398 -> string A | string B | string C
399
400 (void) keyword string head
401 -> double quote =ics();
402
403 (int) string char
404 -> simple string char
405 -> escape sequence
406 -> three octal:n =null_warning(n);
407
408 (int) escape sequence
409 -> "\\a" ='\a';
410 -> "\\b" ='\b';
411 -> "\\f" ='\f';
412 -> "\\n" ='\n';
413 -> "\\r" ='\r';
414 -> "\\t" ='\t';
415 -> "\\v" ='\v';
416 -> "\\\\" ='\\';
417 -> "\\?" = '\?';
418 -> "\\'" ='\'';
419 -> "\\\"" ='"';
420
421 {
422 int null_warning(int n) {
423 extern void warning_here(const char *,...);
424 if (n == 0) log_error("Null character in keyword string");
425 return n;
426 }
427 }
428
429 (int) one octal
430 -> backslash, '0-7':n =n&7;
431
432 (int) two octal
433 -> one octal:n, '0-7':d =n*8 + (d&7);
434
435 (int) three octal
436 -> two octal:n, '0-7':d =n*8 + (d&7);
437
438 (int) octal escape
439 -> one octal | two octal
440
441 (int) hex escape
442 -> "\\x", hex number:x =x;
443
444 (void) string A
445 -> string char:c =acs(c);
446 -> any digit:c =acs(c);
447 -> string, string char:c =acs(c);
448 -> string A, any digit:c =acs(c);
449 -> string B, nonoctal digit:c =acs(c);
450
451 (void) string B
452 -> octal escape:c =acs(null_warning(c));
453 -> string, octal escape:c =acs(null_warning(c));
454
455 (void) string C
456 -> hex escape:c =acs(null_warning(c));
457 -> string, hex escape:c =acs(null_warning(c));
458
459 (int) parameter name
460 -> =0;
461 -> ':', space?, c name =cVariableList << buildAgString();
462
463 (void) simple name
464 -> letter:c =scs(c);
465 -> simple name, letter + digit:c =acs(c);
466
467 (void) c name
468 -> simple name, blank?...
469
470 (void) configuration section
471 -> '[', configuration parameters, right bracket
472
473 (void) configuration parameters
474 -> blank?..., end of line?, [configuration parameter list, end of line?]
475
476 (void) configuration parameter list
477 -> configuration parameter
478 -> configuration parameter list, end of line, configuration parameter
479
480
481 (void) configuration parameter
482 -> name =ConfigParam::set(1, pggErrorHandler); //gp4(1);
483 -> tilde, name =ConfigParam::set(0, pggErrorHandler); //gp4(0);
484 -> name, equals, data type =ConfigParam::set(pggErrorHandler); //gp2();
485 -> name, equals, keyword string =ConfigParam::set(pggErrorHandler); //gp3();
486 -> enum fix, blank?..., equals, keyword string =ConfigParam::set(pggErrorHandler); //gp3();
487 -> name, equals, signed number:n =ConfigParam::set(n, pggErrorHandler); //gp5(n);
488 -> attribute statement
489 -> keyword kluge, name =concat_string(), ConfigParam::set(1, pggErrorHandler); //gp4(1);
490
491 keyword kluge
492 -> "distinguish", blank... =sss("distinguish ");
493
494 (void) attribute statement
495 -> "left", token list =set_prec(1,0);
496 -> "right", token list =set_prec(0,1);
497 -> "nonassoc", token list =set_prec(0,0);
498 -> "sticky", token list =set_sticky();
499 -> "subgrammar", token list =set_subgrammar();
500 -> "hidden", token list =set_hidden();
501 -> new reserve statement, list end //=new_reserve();
502 -> enum statement, list end
503 -> "disregard", blank..., token:t =disregard(t);
504 -> "extend", blank..., "pcb", blank?..., embedded c =extensionStack.push(cSegmentStack.pop());
505 -> "lexeme", token list =set_lexeme();
506 -> "reserve", blank..., "keywords", token list =set_reserved_words();
507 -> "rename", blank..., "macro", blank...,
508 macro name:oldName, blank..., macro name:newName =at(rename_macro_list,oldName,newName);
509 -> "wrapper", blank?..., left brace, wrapper list, right brace
510
511 (int) macro name
512 -> letter =(PCB).pointer-input_base-1;
513 -> macro name, letter + digit
514
515 list end
516 -> [comma | continuation], right brace
517
518 (void) new reserve statement
519 -> "distinguish", blank..., "keywords", blank..., left brace,
520 union:n =distinguishSets.push(ParseTree(n));
521 -> new reserve statement, comma, union:n =distinguishSets.push(ParseTree(n));
522
523 (void) token list
524 -> blank..., left brace, tokens, list end
525
526 (void) tokens
527 -> token:t =sws(t);
528 -> tokens, comma, token:t =aws(t);
529
530 (int) virtual production
531 -> keyword string =vp_s();
532 -> keyword string, '?', blank?... =vp_5(vp_s());
533 -> left brace, vp rules, right brace =vp_1();
534 -> left brace, vp rules, "}...", blank?... =vp_2();
535 -> left bracket, proper vp rule specs, right bracket =vp_3();
536 -> left bracket, proper vp rule specs, "]...", blank?... =vp_4();
537 -> union:n, '?', blank?... =vp_5(form_element_1(n));
538 -> union:n, "?...", blank?... =vp_6(form_element_1(n));
539 -> union:n, ellipsis =vp_7(form_element_1(n));
540 -> left brace, proper vp rule specs, "}/...", blank?... =vp_9();
541 -> left bracket, proper vp rule specs, "]/...", blank?... =vp_10();
542
543 (int) mid rule action
544 -> bang, embedded c =mid_line(proc_spec_4(0));
545 -> bang, c expression, ';', blank?... =mid_line(proc_spec_4(1));
546
547 (void) embedded c
548 -> embedded c head, c code:y, right brace =cSegmentStack.top().end = y;
549
550 (void) embedded c head
551 -> '{', [carriage return?, newline]... =cSegmentStack.push(CSegment()); // =copyon();
552
553 (unsigned char *) c code
554 -> =PCB.pointer;
555 -> c code first, c text =PCB.pointer;
556
557 (void) c code first
558 -> simple c char - eol chars
559 -> c comment
560 -> comment, carriage return?, newline
561 -> c character constant, single quote
562 -> c string constant, double quote
563
564 (void) c text
565 ->
566 -> c text, c char
567
568 (void) c char //c char represents the content of embedded c
569 -> simple c char
570 -> '{', c text, '}'
571 -> c comment
572 -> comment, carriage return?, newline
573 -> c character constant, single quote
574 -> c string constant, double quote
575
576 (void) c expression head
577 -> =cSegmentStack.push(CSegment());
578
579 (void) c expression
580 -> c expression head, c chars =cSegmentStack.top().end = PCB.pointer;
581
582 (void) c chars
583 -> c expression char
584 -> c chars, c expression char
585 -> c chars, blank
586
587 (void) c expression char //c char represents the content of embedded C
588 -> simple c char - ';' - eol chars - blank char
589 -> "\\\n"
590 -> c character constant, single quote
591 -> c string constant, double quote
592
593 (void) c comment
594 -> c comment head, "*/"
595
596 (void) c comment head
597 -> "/*"
598 -> c comment head, ~eof
599
600 (void) c comment, c comment head
601 -> c comment head, c comment =
602 {if (nest_comments) PCB.reduction_token = pgg_c_comment_head_token;}
603
604 (void) c string constant
605 -> double quote, [c literal elem | single quote | backslash, anything]...
606
607 (void) c character constant
608 -> single quote, [c literal elem | double quote | backslash, anything]...
609
610 [
611 hidden {
612 arrow, comma, ellipsis, equals, left brace,
613 left bracket, left parenthesis, minus, plus, right bracket,
614 list end,
615 right brace, right parenthesis, right quote, star, tilde,
616 vertical bar, simple statement, token name,
617 rule spec, pointer, indirect data type, name string,
618 blank, space, next line, white, end of line, sign, simple number,
619 simple set, one octal, two octal, three octal,
620 string A, string B, string C,
621 simple name, c text, c char, c chars, c expression char,
622 c expression head,
623 c comment head,
624 c code, c name,
625 bang,
626 complete statement,
627 rule specs, vp rule specs, additional rule spec,
628 data type, template field, abstract declarator,
629 direct abstract declarator, pointer,
630 name string, proper vp rule specs, additional vp rule spec,
631 new reserve statement, anything, union, intersection, negation,
632 enum fix
633 }
634 ]
635
636 {
637 pgg_pcb_type pgcb;
638 #define PCB pgcb
639
640 #define PARSER_STACK_OVERFLOW parse_stack_overflow()
641 #define SYNTAX_ERROR log_syntax_error()
642 #define GET_CONTEXT CONTEXT.y = PCB.line, CONTEXT.x = PCB.column;
643
644 #define REDUCTION_TOKEN_ERROR reduction_token_error()
645
646 extern AgStack< AgStack<RuleElement> > ruleElementStack;
647
648 AgStack<CSegment> extensionStack;
649 AgStack<CSegment> cSegmentStack;
650 int nPrologueSegments;
651
652 CSegment::CSegment()
653 : begin(PCB.pointer), end(PCB.pointer), line(PCB.line)
654 {
655 LOGSECTION("CSegment::CSegment");
656 // Nothing to do
657 }
658
659 class PggErrorHandler : public ConfigParam::ErrorHandler {
660 void badParam(const char *s){log_error(s);}
661 } pggErrorHandler;
662
663
664 void reduction_token_error(void) {
665 #ifdef INCLUDE_LOGGING
666 LOGSECTION("reduction_token_error");
667 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.reduction_token);
668 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]);
669 #endif
670 assert(0);
671 }
672
673 extern AgString infile_name;
674
675 Error::Error(AgString msg, int contextFlag)
676 : file(infile_name),
677 line(contextFlag? ERROR_CONTEXT.y : PCB.line),
678 column(contextFlag? ERROR_CONTEXT.x : PCB.column),
679 key(warn),
680 message(msg)
681 {
682 LOGSECTION("Error::Error(AgString, int)");
683 LOGV(PCB.line) LCV(PCB.column) LCV(contextFlag) LCV(msg.pointer());
684 LOGV(ERROR_CONTEXT.x) LCV(ERROR_CONTEXT.y);
685 // Nothing here
686 }
687
688 Error::Error(int l, int c, AgString msg)
689 : file(infile_name),
690 line(l),
691 column(c),
692 key(warn),
693 message(msg)
694 {
695 LOGSECTION("Error::Error(int, int, AgString)");
696 // Nothing here
697 }
698
699 extern tsd *rename_macro_list;
700 extern int parse_abort_flag;
701
702 void parse_stack_overflow(void) {
703 reset_stk();
704 log_error("Nesting too deep. Analysis aborted.");
705 errorList.top().setFatal();
706 parse_abort_flag = 1;
707 PCB.exit_flag = AG_SEMANTIC_ERROR_CODE;
708 }
709
710 extern int character_seen;
711 extern int enum_base;
712 extern unsigned char *input_base;
713 extern int precedence_level;
714 extern int syntax_error_flag;
715
716 CharSetExpression *ss2(void);
717
718 void acs(int);
719 void aws(int);
720 void atkn(Token);
721 void definition_1(CharSetExpression *);
722 void definition_2(int);
723 void definition_3(int);
724 int form_element_1(CharSetExpression *);
725 int form_spec_2(int, int);
726 int form1(void);
727 int form2(void);
728 int head_list_1(int);
729 int head_list_2(int);
730 static int head_list_3(int);
731 void ics(void);
732 int identify_node(CharSetExpression *);
733 void iws(void);
734 int makeRule(const AgIndexedContainer<RuleElement> &);
735 int mid_line(int);
736 int null_warning(int);
737 int proc_spec_4(int);
738 void production(int);
739 void range(int, int);
740 void scs(int);
741 static void set_prec(int,int);
742 void sws(int);
743 int vp_form3(int);
744 int vp_s(void);
745 int vp_1(void);
746 int vp_2(void);
747 int vp_3(void);
748 int vp_4(void);
749 int vp_5(int);
750 int vp_6(int);
751 int vp_7(int);
752 int vp_8(int);
753 int vp_8a(int);
754 int vp_9(void);
755 int vp_10(void);
756
757 int *disregard_list = NULL;
758 int n_disregard_list = 0;
759 int nClassWrappers = 0;
760
761 static void disregard(int tn) {
762 LOGSECTION("disregard");
763 iws();
764 if (n_disregard_list) {
765 int *p = disregard_list;
766 while (n_disregard_list--) aws(*p++);
767 DEALLOCATE(disregard_list);
768 }
769 xws(tn);
770 disregard_list = build_list();
771 n_disregard_list = fis();
772 }
773
774 static void log_syntax_error(void) {
775 LOGSECTION("log_syntax_error");
776
777 #ifdef INCLUDE_LOGGING
778 {
779 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number);
780 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]);
781 }
782 #endif
783 int flag = PCB.error_frame_token == pgg_c_comment_token ||
784 PCB.error_frame_token == pgg_embedded_c_token;
785 LOGV(flag);
786 reset_stk();
787
788 #ifdef INCLUDE_LOGGING
789 {
790 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number);
791 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]);
792 }
793 #endif
794 ssprintf("%s in %s", PCB.error_message, pgg_token_names[PCB.error_frame_token]);
795 LOGS(string_base);
796 errorList.push(Error(string_base, flag && PCB.token_number == pgg_eof_token));
797 rcs();
798 #ifdef INCLUDE_LOGGING
799 {
800 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number);
801 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]);
802 }
803 #endif
804 LOGS("error logged");
805 errorList.top().setFatal();
806 LOGS("fatal flag set");
807 syntax_error_flag++;
808 #ifdef INCLUDE_LOGGING
809 {
810 LOGV(PCB.sn) LCV(PCB.ssx) LCV(PCB.token_number);
811 for (int i = 0; i < PCB.ssx; i++) LOGV(i) LCV(PCB.ss[i]);
812 }
813 #endif
814 if (errorList.size() < 50) return;
815 log_error("Too many errors. Parse aborted.");
816 errorList.top().setFatal();
817 PCB.exit_flag = AG_SYNTAX_ERROR_CODE;
818 }
819
820 static int head_list_3(int type) {
821 LOGSECTION("head_list_3");
822 LOGV(type);
823 int i, n = tis();
824 for (i = 0; i < n; i ++) {
825 Token token(list_base[i]);
826 int ptt = token->value_type;
827 LOGV(ptt) LCV(type);
828 if (ptt && ptt != type) {
829 ssprintf("Type Redefinition of T%03d: ", (int) token);
830 atkn(token);
831 log_error();
832 }
833 token->value_type = type;
834 /*
835 if (ptt == 0 && token->rp_arg && type == void_token_type) {
836 //ssprintf("Void token, %s, used as parameter", dict_str(tkn_dict,token->token_name));
837 ssprintf("Void token, %s, used as parameter", token->token_name->string.pointer());
838 log_error();
839 }
840 */
841 }
842 return type;
843 }
844
845 static void set_prec(int left, int right){
846 LOGSECTION("set_prec");
847 int n = tis();
848 precedence_level++;
849 while (n--) {
850 Token token(list_base[n]);
851 token->left_associative = left;
852 token->right_associative = right;
853 token->precedence_level = precedence_level;
854 }
855 rws();
856 }
857
858 static void set_sticky(void){
859 LOGSECTION("set_sticky");
860 int n = tis();
861 while (n--) {
862 Token token(list_base[n]);
863 token->sticky = 1;
864 }
865 rws();
866 }
867
868 static void set_subgrammar(void){
869 LOGSECTION("set_subgrammar");
870 int n = tis();
871 while (n--) {
872 Token token = list_base[n];
873 token->subgrammar = 1;
874 }
875 rws();
876 }
877
878 void set_hidden(void) {
879 LOGSECTION("set_hidden");
880 int *lb = list_base;
881 int n = tis();
882 //while (n--) map_token_number[*lb++].fine_structure = 1;
883 while (n--) Token(*lb++)->fine_structure = 1;
884 rws();
885 }
886
887 void set_lexeme(void) {
888 LOGSECTION("set_lexeme");
889 int n = tis();
890 while (n--) {
891 Token token = list_base[n];
892 token->lexeme = 1;
893 }
894 rws();
895 }
896
897 void set_reserved_words(void) {
898 LOGSECTION("set_reserved_words");
899 int n = tis();
900 while (n--) {
901 Token(list_base[n])->reserved_word = 1;
902 }
903 rws();
904 }
905
906 void parse(void) {
907 pgcb.pointer = input_base;
908 pgg();
909 }
910 }
911