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