2 * antlr.g -- PCCTS Version 1.xx ANTLR
4 * $Id: antlr.g,v 1.7 95/10/05 11:57:12 parrt Exp $
7 * Parse an antlr input grammar and build a syntax-diagram.
9 * Written in itself (needs at least 1.06 to work)
13 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
14 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
15 * company may do whatever they wish with source code distributed with
16 * PCCTS or the code generated by PCCTS, including the incorporation of
17 * PCCTS, or its output, into commerical software.
19 * We encourage users to develop software with PCCTS. However, we do ask
20 * that credit is given to us for developing PCCTS. By "credit",
21 * we mean that if you incorporate our source code into one of your
22 * programs (commercial product, research project, or otherwise) that you
23 * acknowledge this fact somewhere in the documentation, research report,
24 * etc... If you like PCCTS and have developed a nice tool with the
25 * output, please mention that you developed it using PCCTS. In
26 * addition, we ask that this header remain intact in our source code.
27 * As long as these guidelines are kept, we expect to continue enhancing
28 * this system and expect to make other tools available as they are
33 * Parr Research Corporation
34 * with Purdue University and AHPCRC, University of Minnesota
48 #define zzcr_attr(attr,tok,t)
53 static void chkToken(char *, char *, char *, int);
55 static void chkToken();
58 static int class_nest_level = 0;
60 extern set attribsRefdFromAction;
61 extern int UsedOldStyleAttrib;
62 extern int UsedNewStyleLabel;
66 /* maintained, but not used for now */
67 set AST_nodes_refd_in_actions = set_init;
69 set attribsRefdFromAction;
70 int UsedOldStyleAttrib = 0;
71 int UsedNewStyleLabel = 0;
73 char *inline_set(char *);
80 #token QuotedTerm "\"" << zzmode(START); >>
83 warn("eoln found in string");
86 #token "\\[\n\r]" << zzline++; zzmore(); >>
87 #token "\\~[]" << zzmore(); >>
88 #token "~[\n\r\"\\]+" << zzmore(); >>
90 #lexclass ACTION_STRINGS
91 #token "\"" << zzmode(ACTIONS); zzmore(); >>
94 warn("eoln found in string (in user action)");
97 #token "\\[\n\r]" << zzline++; zzmore(); >>
98 #token "\\~[]" << zzmore(); >>
99 #token "~[\n\r\"\\]+" << zzmore(); >>
101 #lexclass ACTION_CHARS
102 #token "'" << zzmode(ACTIONS); zzmore(); >>
105 warn("eoln found in char literal (in user action)");
108 #token "\\~[]" << zzmore(); >>
109 #token "~[\n\r'\\]+" << zzmore(); >>
111 #lexclass ACTION_COMMENTS
112 #token "\*/" << zzmode(ACTIONS); zzmore(); >>
113 #token "\*" << zzmore(); >>
114 #token "[\n\r]" << zzline++; zzmore(); DAWDLE; >>
115 #token "~[\n\r\*]+" << zzmore(); >>
117 #lexclass TOK_DEF_COMMENTS
118 #token "\*/" << zzmode(PARSE_ENUM_FILE);
120 #token "\*" << zzmore(); >>
121 #token "[\n\r]" << zzline++; zzmore(); DAWDLE; >>
122 #token "~[\n\r\*]+" << zzmore(); >>
124 #lexclass TOK_DEF_CPP_COMMENTS
125 #token "[\n\r]" << zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE; >>
126 #token "~[\n\r]+" << zzskip(); >>
128 #lexclass ACTION_CPP_COMMENTS
129 #token "[\n\r]" << zzline++; zzmode(ACTIONS); zzmore(); DAWDLE; >>
130 #token "~[\n\r]+" << zzmore(); >>
132 #lexclass CPP_COMMENTS
133 #token "[\n\r]" << zzline++; zzmode(START); zzskip(); DAWDLE; >>
134 #token "~[\n\r]+" << zzskip(); >>
137 #token "\*/" << zzmode(START); zzskip(); >>
138 #token "\*" << zzskip(); >>
139 #token "[\n\r]" << zzline++; zzskip(); DAWDLE; >>
140 #token "~[\n\r\*]+" << zzskip(); >>
143 * This lexical class accepts actions of type [..] and <<..>>
145 * It translates the following special items for C:
147 * $j --> "zzaArg(current zztasp, j)"
148 * $i.j --> "zzaArg(zztaspi, j)"
149 * $i.nondigit> "zzaArg(current zztasp, i).nondigit"
151 * $alnum --> "alnum" (used to ref parameters)
153 * $retval --> "_retv.retval" if > 1 return values else "_retv"
154 * $[token, text] --> "zzconstr_attr(token, text)"
155 * $[] --> "zzempty_attr()"
157 * It translates the following special items for C++:
158 * (attributes are now stored with 'Token' and $i's are only
159 * pointers to the Tokens. Rules don't have attributes now.)
161 * $j --> "_tbj" where b is the block level
163 * $j->nondigit> "_tbj->nondigit"
165 * $alnum --> "alnum" (used to ref parameters)
167 * $retval --> "_retv.retval" if > 1 return values else "_retv"
168 * $[token, text] --> invalid
174 * #i --> "zzastArg(i)"
175 * #[args] --> "zzmk_ast(zzastnew(), args)"
176 * #[] --> "zzastnew()"
177 * #( root, child1, ..., childn )
178 * --> "zztmake(root, child1, ...., childn, NULL)"
184 * #i --> "_astbi" where b is the block level
185 * #alnum --> "alnum_ast" (used to ref #label)
186 * #[args] --> "new AST(args)"
188 * #( root, child1, ..., childn )
189 * --> "AST::tmake(root, child1, ...., childn, NULL)"
199 * A stack is used to nest action terminators because they can be nested
200 * like crazy: << #[$[..],..] >>
203 #token Action "\>\>" << /* these do not nest */
210 err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
213 #token Pred "\>\>?" << /* these do not nest */
219 err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE));
222 #token PassAction "\]" << if ( topint() == ']' ) {
224 if ( istackempty() ) /* terminate action */
230 err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
234 /* terminate $[..] and #[..] */
235 if ( GenCC ) zzreplstr("))");
240 else if ( topint() == '|' ) { /* end of simple [...] */
246 #token "consumeUntil\( [\ \t]* \{~[\}]+\} [\ \t]* \)"
249 zzreplstr(inline_set(zzbegexpr+
250 strlen("consumeUntil(")));
252 #token "consumeUntil\( ~[\)]+ \)"
254 #token "[\n\r]" << zzline++; zzmore(); DAWDLE; >>
255 #token "\>" << zzmore(); >>
256 #token "$" << zzmore(); >>
257 #token "$$" << if ( !GenCC ) {zzreplstr("zzaRet"); zzmore();}
258 else err("$$ use invalid in C++ mode"); >>
260 #token "$\[\]" << if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();}
261 else err("$[] use invalid in C++ mode"); >>
264 if ( !GenCC ) zzreplstr("zzconstr_attr(");
265 else err("$[..] use invalid in C++ mode");
269 static char buf[100];
270 if ( strlen(zzbegexpr)>(size_t)85 )
271 fatal("$i attrib ref too big");
272 set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction);
273 if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s)",
274 BlkLevel-1,zzbegexpr+1);
275 else sprintf(buf,"_t%d%s",
276 BlkLevel-1,zzbegexpr+1);
279 UsedOldStyleAttrib = 1;
280 if ( UsedNewStyleLabel )
281 err("cannot mix old-style $i with new-style labels");
284 #token "$[0-9]+." <<{
285 static char buf[100];
286 if ( strlen(zzbegexpr)>(size_t)85 )
287 fatal("$i.field attrib ref too big");
288 zzbegexpr[strlen(zzbegexpr)-1] = ' ';
289 set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction);
290 if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s).",
291 BlkLevel-1,zzbegexpr+1);
292 else sprintf(buf,"_t%d%s.",
293 BlkLevel-1,zzbegexpr+1);
296 UsedOldStyleAttrib = 1;
297 if ( UsedNewStyleLabel )
298 err("cannot mix old-style $i with new-style labels");
301 #token "$[0-9]+.[0-9]+" <<{
302 static char buf[100];
303 static char i[20], j[20];
305 if (strlen(zzbegexpr)>(size_t)85) fatal("$i.j attrib ref too big");
306 for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) {
308 fatalFL("i of $i.j attrib ref too big",
309 FileStr[CurFile], zzline );
313 for (p++, q= &j[0]; *p!='\0'; p++) {
315 fatalFL("j of $i.j attrib ref too big",
316 FileStr[CurFile], zzline );
320 if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j);
321 else sprintf(buf,"_t%s%s",i,j);
324 UsedOldStyleAttrib = 1;
325 if ( UsedNewStyleLabel )
326 err("cannot mix old-style $i with new-style labels");
329 #token "$[_a-zA-Z][_a-zA-Z0-9]*"
330 <<{ static char buf[300]; LabelEntry *el;
332 if ( CurRule != NULL &&
333 strcmp(CurRule, &zzbegexpr[1])==0 ) {
334 if ( !GenCC ) zzreplstr("zzaRet");
336 else if ( CurRetDef != NULL &&
337 strmember(CurRetDef, &zzbegexpr[1])) {
338 if ( HasComma( CurRetDef ) ) {
339 require (strlen(zzbegexpr)<=(size_t)285,
340 "$retval attrib ref too big");
341 sprintf(buf,"_retv.%s",&zzbegexpr[1]);
344 else zzreplstr("_retv");
346 else if ( CurParmDef != NULL &&
347 strmember(CurParmDef, &zzbegexpr[1])) {
350 else if ( Elabel==NULL ) {
351 { err("$-variables in actions outside of rules are not allowed"); }
352 } else if ( (el=(LabelEntry *)hash_get(Elabel, &zzbegexpr[1]))!=NULL ) {
353 if ( GenCC && (el->elem==NULL || el->elem->ntype==nRuleRef) )
354 { err(eMsg1("There are no token ptrs for rule references: '$%s'",&zzbegexpr[1])); }
357 warn(eMsg1("$%s not parameter, return value, or element label",&zzbegexpr[1]));
361 #token "#0" << zzreplstr("(*_root)"); zzmore(); chkGTFlag(); >>
362 #token "#\[\]" << if ( GenCC ) {zzreplstr("(new AST)");}
363 else {zzreplstr("zzastnew()");} zzmore();
366 #token "#\(\)" << zzreplstr("NULL"); zzmore(); chkGTFlag(); >>
368 static char buf[100];
369 if ( strlen(zzbegexpr)>(size_t)85 )
370 fatal("#i AST ref too big");
371 if ( GenCC ) sprintf(buf,"_ast%d%s",BlkLevel-1,zzbegexpr+1);
372 else sprintf(buf,"zzastArg(%s)",zzbegexpr+1);
375 set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions);
379 #token "#[_a-zA-Z][_a-zA-Z0-9]*"
381 if ( !(strcmp(zzbegexpr, "#ifdef")==0 ||
382 strcmp(zzbegexpr, "#if")==0 ||
383 strcmp(zzbegexpr, "#else")==0 ||
384 strcmp(zzbegexpr, "#endif")==0 ||
385 strcmp(zzbegexpr, "#ifndef")==0 ||
386 strcmp(zzbegexpr, "#define")==0 ||
387 strcmp(zzbegexpr, "#pragma")==0 ||
388 strcmp(zzbegexpr, "#undef")==0 ||
389 strcmp(zzbegexpr, "#import")==0 ||
390 strcmp(zzbegexpr, "#line")==0 ||
391 strcmp(zzbegexpr, "#include")==0 ||
392 strcmp(zzbegexpr, "#error")==0) )
394 static char buf[100];
395 sprintf(buf, "%s_ast", zzbegexpr+1);
403 if ( GenCC ) zzreplstr("(new AST(");
404 else zzreplstr("zzmk_ast(zzastnew(),");
410 if ( GenCC ) zzreplstr("ASTBase::tmake(");
411 else zzreplstr("zztmake(");
415 #token "#" << zzmore(); >>
419 else if ( topint()==')' ) {
422 else if ( topint()=='}' ) {
424 /* terminate #(..) */
425 zzreplstr(", NULL)");
430 pushint('|'); /* look for '|' to terminate simple [...] */
438 #token "\\\]" << zzreplstr("]"); zzmore(); >>
439 #token "\\\)" << zzreplstr(")"); zzmore(); >>
440 #token "\\>" << zzreplstr(">"); zzmore(); >>
443 #token "'" << zzmode(ACTION_CHARS); zzmore();>>
444 #token "\"" << zzmode(ACTION_STRINGS); zzmore();>>
445 #token "\\$" << zzreplstr("$"); zzmore(); >>
446 #token "\\#" << zzreplstr("#"); zzmore(); >>
447 #token "\\[\n\r]" << zzline++; zzmore(); >>
448 #token "\\~[\]\)>$#]" << zzmore(); >> /* escaped char, always ignore */
449 #token "/" << zzmore(); >>
450 #token "/\*" << zzmode(ACTION_COMMENTS); zzmore(); >>
451 #token "\*/" << warn("Missing /*; found dangling */ in action"); zzmore(); >>
452 #token "//" << zzmode(ACTION_CPP_COMMENTS); zzmore(); >>
453 #token "~[\n\r\)\(\\$#\>\]\[\"'/]+" << zzmore(); >>
456 #token "[\t\ ]+" << zzskip(); >> /* Ignore White */
457 #token "[\n\r]" << zzline++; zzskip(); >> /* Track Line # */
458 #token "\[" << zzmode(ACTIONS); zzmore();
461 #token "\<\<" << action_file=CurFile; action_line=zzline;
462 zzmode(ACTIONS); zzmore();
465 #token "\"" << zzmode(STRINGS); zzmore(); >>
466 #token "/\*" << zzmode(COMMENTS); zzskip(); >>
467 #token "\*/" << warn("Missing /*; found dangling */"); zzskip(); >>
468 #token "//" << zzmode(CPP_COMMENTS); zzskip(); >>
469 #token "\>\>" << warn("Missing <<; found dangling \\>\\>"); zzskip(); >>
471 #token "\@" <<FoundException = 1;>>
473 << /* L o o k F o r A n o t h e r F i l e */
476 new_input = NextFile();
477 if ( new_input == NULL ) { NLA=Eof; return; }
481 zzskip(); /* Skip the Eof (@) char i.e continue */
487 #errclass "grammar-element" { element }
488 #errclass "meta-symbol" { "\}" "!" ";" "\|" "\~" "^" "\)" }
491 * Get a grammar -- Build a list of rules like:
501 grammar : <<Graph g;>>
504 if ( HdrAction==NULL ) {
505 HdrAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
506 require(HdrAction!=NULL, "rule grammar: cannot allocate header action");
507 strcpy(HdrAction, LATEXT(1));
509 else warn("additional #header statement ignored");
511 | "#parser" QuotedTerm
514 warn("#parser meta-op incompatible with -CC; ignored");
517 if ( strcmp(ParserName,"zzparser")==0 ) {
518 ParserName=StripQuotes(mystrdup(LATEXT(1)));
519 if ( RulePrefix[0]!='\0' )
521 warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored");
525 else warn("additional #parser statement ignored");
528 | "#tokdefs" QuotedTerm
531 zzantlr_state st; FILE *f; struct zzdlg_state dst;
532 UserTokenDefsFile = mystrdup(LATEXT(1));
533 zzsave_antlr_state(&st);
534 zzsave_dlg_state(&dst);
535 fname = mystrdup(LATEXT(1));
536 f = fopen(StripQuotes(fname), "r");
537 if ( f==NULL ) {warn(eMsg1("cannot open token defs file '%s'", fname+1));}
539 ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE);
542 zzrestore_antlr_state(&st);
543 zzrestore_dlg_state(&dst);
548 UserAction *ua = newUserAction(LATEXT(1));
549 ua->file = action_file; ua->line = action_line;
550 if ( class_nest_level>0 ) list_add(&class_before_actions, ua);
551 else list_add(&BeforeActions, ua);
558 | default_exception_handler
562 if ( class_nest_level==0 )
563 warn("missing class definition for trailing '}'");
567 rule <<g=$3; SynDiag = (Junction *) $3.left;>>
568 ( rule <<if ( $1.left!=NULL ) {g.right = NULL; g = Or(g, $1);}>>
576 if ( class_nest_level==0 )
577 warn("missing class definition for trailing '}'");
583 UserAction *ua = newUserAction(LATEXT(1));
584 ua->file = action_file; ua->line = action_line;
585 if ( class_nest_level>0 ) list_add(&class_after_actions, ua);
586 else list_add(&AfterActions, ua);
594 if ( class_nest_level==0 )
595 warn("missing class definition for trailing '}'");
601 <<CannotContinue=TRUE;>>
604 : <<int go=1; char name[MaxRuleName+1];>>
606 ( NonTerminal <<if(go) strncpy(name,LATEXT(1),MaxRuleName);>>
607 | TokenTerm <<if(go) strncpy(name,LATEXT(1),MaxRuleName);>>
610 if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0
612 err("only one grammar class allowed in this release");
615 else strcpy(CurrentClassName, name);
617 <<if ( !GenCC ) { err("class meta-op used without C++ option"); }>>
620 no_classes_found = 0;
621 if ( class_nest_level>=1 ) {warn("cannot have nested classes");}
622 else class_nest_level++;
625 <<CannotContinue=TRUE;>>
628 * Build -o-->o-R-o-->o- where -o-R-o- is the block from rule 'block'.
629 * Construct the RuleBlk front and EndRule node on the end of the
630 * block. This is used to add FOLLOW pointers to the rule end. Add the
631 * new rule name to the Rname hash table and sets its rulenum.
632 * Store the parameter definitions if any are found.
634 * Note that locks are required on the RuleBlk and EndRule nodes to thwart
635 * infinite recursion.
637 * Return the left graph pointer == NULL to indicate error/dupl rule def.
640 ListNode *ex_groups = NULL;
642 RuleEntry *q; Junction *p; Graph r; int f, l; ECnode *e;
643 set toksrefd, rulesrefd;
644 char *pdecl=NULL, *ret=NULL, *a; CurRetDef = CurParmDef = NULL;
646 CurElementLabels = NULL;
647 /* We want a new element label hash table for each rule */
648 if ( Elabel!=NULL ) killHashTable(Elabel);
649 Elabel = newHashTable();
650 attribsRefdFromAction = empty;
654 if ( hash_get(Rname, LATEXT(1))!=NULL ) {
655 err(eMsg1("duplicate rule definition: '%s'",LATEXT(1)));
660 q = (RuleEntry *)hash_add(Rname,
662 (Entry *)newRuleEntry(LATEXT(1)));
666 f = CurFile; l = zzline;
669 { "!" <<if ( q!=NULL ) q->noAST = TRUE;>> }
673 << pdecl = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
674 require(pdecl!=NULL, "rule rule: cannot allocate param decl");
675 strcpy(pdecl, LATEXT(1));
681 << ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
682 require(ret!=NULL, "rule rule: cannot allocate ret type");
683 strcpy(ret, LATEXT(1));
687 { QuotedTerm <<if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1));>> }
689 if ( GenEClasseForRules && q!=NULL ) {
691 require(e!=NULL, "cannot allocate error class node");
692 if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);}
694 if ( Tnum( a ) == 0 )
696 e->tok = addTname( a );
697 list_add(&eclasses, (char *)e);
698 if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
699 /* refers to itself */
700 list_add(&(e->elist), mystrdup(q->str));
703 warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a));
704 if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
711 block[&toksrefd, &rulesrefd]
713 CurRuleBlk = (Junction *)r.left;
714 CurRuleBlk->blockid = CurBlockID;
715 CurRuleBlk->jtype = RuleBlk;
716 if ( q!=NULL ) CurRuleBlk->rname = q->str;
717 CurRuleBlk->file = f;
718 CurRuleBlk->line = l;
719 CurRuleBlk->pdecl = pdecl;
720 CurRuleBlk->ret = ret;
721 CurRuleBlk->lock = makelocks();
722 CurRuleBlk->pred_lock = makelocks();
723 CurRuleBlk->tokrefs = toksrefd;
724 CurRuleBlk->rulerefs = rulesrefd;
725 p = newJunction(); /* add EndRule Node */
726 ((Junction *)r.right)->p1 = (Node *)p;
727 r.right = (Node *) p;
729 p->lock = makelocks();
730 p->pred_lock = makelocks();
732 if ( q!=NULL ) q->rulenum = NumRules;
738 << a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
739 require(a!=NULL, "rule rule: cannot allocate error action");
740 strcpy(a, LATEXT(1));
741 CurRuleBlk->erraction = a;
744 ( exception_group > [eg]
746 list_add(&CurExGroups, (void *)eg);
747 if ( eg->label=='\0' ) q->has_rule_exception = 1;
751 <<if ( q==NULL ) $0.left = NULL; else $0 = $7;>>
752 <<CurRuleNode = NULL;>>
753 <<CurRuleBlk->exceptions = CurExGroups;>>
754 <<CurRuleBlk->el_labels = CurElementLabels;>>
756 <<CannotContinue=TRUE;>>
759 pragma : "#pragma" "dup\-labeled\-tokens"
760 <<Pragma_DupLabeledTokens=1;>>
764 laction : <<char *a;>>
768 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
769 require(a!=NULL, "rule laction: cannot allocate action");
770 strcpy(a, LATEXT(1));
771 list_add(&LexActions, a);
774 <<CannotContinue=TRUE;>>
776 aLexclass: "#lexclass" TokenTerm <<lexclass(mystrdup(LATEXT(1)));>>
778 <<CannotContinue=TRUE;>>
780 error : <<char *t=NULL; ECnode *e; int go=1; TermEntry *p;>>
782 (<<;>> TokenTerm <<t=mystrdup(LATEXT(1));>>
783 | QuotedTerm <<t=mystrdup(LATEXT(1));>>
786 require(e!=NULL, "cannot allocate error class node");
787 e->lexclass = CurrentLexClass;
788 if ( Tnum( (t=StripQuotes(t)) ) == 0 )
790 if ( hash_get(Texpr, t) != NULL )
791 warn(eMsg1("errclass name conflicts with regular expression '%s'",t));
792 e->tok = addTname( t );
793 set_orel(e->tok, &imag_tokens);
794 require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
795 "hash table mechanism is broken");
796 p->classname = 1; /* entry is errclass name, not token */
797 list_add(&eclasses, (char *)e);
801 warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t));
807 ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>>
808 | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
809 | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
811 <<if ( go ) list_add(&(e->elist), t);>>
813 ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>>
814 | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
815 | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
817 <<if ( go ) list_add(&(e->elist), t);>>
821 <<CannotContinue=TRUE;>>
823 tclass : <<char *t=NULL; TCnode *e; int go=1,tok; TermEntry *p, *term;>>
824 "#tokclass" TokenTerm <<t=mystrdup(LATEXT(1));>>
826 require(e!=NULL, "cannot allocate token class node");
827 e->lexclass = CurrentLexClass;
828 if ( Tnum( t ) == 0 )
830 e->tok = addTname( t );
831 set_orel(e->tok, &imag_tokens);
832 set_orel(e->tok, &tokclasses);
833 require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
834 "hash table mechanism is broken");
835 p->classname = 1; /* entry is class name, not token */
836 p->tclass = e; /* save ptr to this tclass def */
837 list_add(&tclasses, (char *)e);
841 warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t));
850 term = (TermEntry *) hash_get(Tname, LATEXT(1));
851 if ( term==NULL && UserDefdTokens ) {
852 err("implicit token definition not allowed with #tokdefs");
855 else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));}
859 term = (TermEntry *) hash_get(Texpr, LATEXT(1));
860 if ( term==NULL && UserDefdTokens ) {
861 err("implicit token definition not allowed with #tokdefs");
864 else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));}
867 <<if ( go ) list_add(&(e->tlist), t);>>
871 <<CannotContinue=TRUE;>>
873 token : <<char *t=NULL, *e=NULL, *a=NULL; int tnum=0;>>
875 { TokenTerm <<t=mystrdup(LATEXT(1));>>
876 { "=" "[0-9]+" /* define the token type number */
877 <<tnum = atoi(LATEXT(1));>>
880 { QuotedTerm <<e=mystrdup(LATEXT(1));>> }
883 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
884 require(a!=NULL, "rule token: cannot allocate action");
885 strcpy(a, LATEXT(1));
888 <<chkToken(t, e, a, tnum);>>
890 <<CannotContinue=TRUE;>>
892 block[set *toksrefd, set *rulesrefd]
896 int saveinalt = inAlt;
900 set_clr(AST_nodes_refd_in_actions);
903 saveblah = attribsRefdFromAction;
904 attribsRefdFromAction = empty;
906 alt[toksrefd,rulesrefd] <<b = g = $1;>>
908 if ( ((Junction *)g.left)->p1->ntype == nAction )
910 if ( !((ActionNode *)(((Junction *)g.left)->p1))->is_predicate )
912 ((ActionNode *)(((Junction *)g.left)->p1))->init_action = TRUE;
915 ((Junction *)g.left)->blockid = CurBlockID;
918 ( exception_group > [eg]
921 eg->altID = makeAltID(CurBlockID,CurAltNum);
922 CurAltStart->exception_label = eg->altID;
923 list_add(&CurExGroups, (void *)eg);
930 alt[toksrefd,rulesrefd] <<g = Or(g, $2);>>
932 ((Junction *)g.left)->blockid = CurBlockID;
935 ( exception_group > [eg]
938 eg->altID = makeAltID(CurBlockID,CurAltNum);
939 CurAltStart->exception_label = eg->altID;
940 list_add(&CurExGroups, (void *)eg);
949 <<attribsRefdFromAction = saveblah; inAlt = saveinalt;>>
951 <<CannotContinue=TRUE;>>
953 alt[set *toksrefd, set *rulesrefd]
954 : <<int n=0,ne=0; Graph g; int e_num=0, not=0; Node *node; set elems, dif;
955 int first_on_line = 1, use_def_MT_handler = 0;
956 g.left=NULL; g.right=NULL;
961 { "\@" /* handle MismatchedToken signals with default handler */
962 <<use_def_MT_handler = 1;>>
965 { <<not=0;>> "\~" <<not=1;>> }
966 element[not, first_on_line, use_def_MT_handler] > [node]
967 <<if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0;>>
969 if ( $2.left!=NULL ) {
973 if ( node->ntype!=nAction ) e_num++;
974 /* record record number of all rule and token refs */
975 if ( node->ntype==nToken ) {
976 TokNode *tk = (TokNode *)((Junction *)$2.left)->p1;
978 set_orel(e_num, &elems);
980 else if ( node->ntype==nRuleRef ) {
981 RuleRefNode *rn = (RuleRefNode *)((Junction *)$2.left)->p1;
983 set_orel(e_num, $rulesrefd);
989 <<if ( n == 0 ) g = emptyAlt();
991 /* We want to reduce number of LT(i) calls and the number of
992 * local attribute variables in C++ mode (for moment, later we'll
993 * do for C also). However, if trees are being built, they
994 * require most of the attrib variables to create the tree nodes
995 * with; therefore, we gen a token ptr for each token ref in C++
997 if ( GenCC && !GenAST )
999 /* This now free's the temp set -ATG 5/6/95 */
1001 temp = set_and(elems, attribsRefdFromAction);
1002 set_orin($toksrefd, temp);
1005 else set_orin($toksrefd, elems);
1007 dif = set_dif(attribsRefdFromAction, elems);
1008 if ( set_deg(dif)>0 )
1009 err("one or more $i in action(s) refer to non-token elements");
1013 set_free(attribsRefdFromAction);
1017 <<CannotContinue=TRUE;>>
1019 element_label > [LabelEntry *label]
1020 : <<TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;>>
1021 LABEL <<lab = mystrdup(LATEXT(1));>>
1023 UsedNewStyleLabel = 1;
1024 if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i");
1025 t = (TermEntry *) hash_get(Tname, lab);
1026 if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab);
1027 if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab);
1029 err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab));
1032 else if ( r!=NULL ) {
1033 err(eMsg1("label definition clashes with rule definition: '%s'", lab));
1037 /* we don't clash with anybody else */
1038 l = (LabelEntry *) hash_get(Elabel, lab);
1039 if ( l==NULL ) { /* ok to add new element label */
1040 l = (LabelEntry *)hash_add(Elabel,
1042 (Entry *)newLabelEntry(lab));
1043 /* add to list of element labels for this rule */
1044 list_add(&CurElementLabels, (void *)lab);
1048 err(eMsg1("label definitions must be unique per rule: '%s'", lab));
1056 element[int not, int first_on_line, int use_def_MT_handler] > [Node *node]
1059 Predicate *pred = NULL;
1060 int local_use_def_MT_handler=0;
1063 set toksrefd, rulesrefd;
1065 TokNode *p=NULL; RuleRefNode *q; int approx=0;
1066 LabelEntry *label=NULL;
1069 {element_label>[label]}
1072 term = (TermEntry *) hash_get(Tname, LATEXT(1));
1073 if ( term==NULL && UserDefdTokens ) {
1074 err("implicit token definition not allowed with #tokdefs");
1075 $$.left = $$.right = NULL;
1078 $$ = buildToken(LATEXT(1));
1079 p=((TokNode *)((Junction *)$$.left)->p1);
1080 term = (TermEntry *) hash_get(Tname, LATEXT(1));
1081 require( term!= NULL, "hash table mechanism is broken");
1082 p->tclass = term->tclass;
1083 p->complement = $not;
1084 if ( label!=NULL ) {
1085 p->el_label = label->str;
1086 label->elem = (Node *)p;
1092 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1094 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1098 if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) )
1099 list_add(&MetaTokenNodes, (void *)p);
1101 ( "^" <<if ( p!=NULL ) p->astnode=ASTroot;>>
1102 | <<if ( p!=NULL ) p->astnode=ASTchild;>>
1103 | "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>>
1105 { "\@" <<local_use_def_MT_handler = 1;>> }
1107 if ( p!=NULL && $first_on_line ) {
1108 CurAltStart = (Junction *)$$.left;
1109 p->altstart = CurAltStart;
1112 p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler;
1117 term = (TermEntry *) hash_get(Texpr, LATEXT(1));
1118 if ( term==NULL && UserDefdTokens ) {
1119 err("implicit token definition not allowed with #tokdefs");
1120 $$.left = $$.right = NULL;
1123 $$ = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);
1124 p->complement = $not;
1125 if ( label!=NULL ) {
1126 p->el_label = label->str;
1127 label->elem = (Node *)p;
1133 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1135 <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1138 ( "^" <<if ( p!=NULL ) p->astnode=ASTroot;>>
1139 | <<if ( p!=NULL ) p->astnode=ASTchild;>>
1140 | "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>>
1142 { "\@" <<local_use_def_MT_handler = 1;>> }
1144 if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) )
1145 list_add(&MetaTokenNodes, (void *)p);
1148 if ( $first_on_line ) {
1149 CurAltStart = (Junction *)$$.left;
1150 p->altstart = CurAltStart;
1153 p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler;
1157 | <<if ( $not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')");>>
1159 <<$$ = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);>>
1160 ( "^" <<p->astnode=ASTroot;>>
1161 | <<p->astnode=ASTchild;>>
1162 | "!" <<p->astnode=ASTexclude;>>
1164 <<list_add(&MetaTokenNodes, (void *)p);>>
1166 if ( $first_on_line ) {
1167 CurAltStart = (Junction *)$$.left;
1168 p->altstart = CurAltStart;
1169 if ( label!=NULL ) {
1170 p->el_label = label->str;
1171 label->elem = (Node *)p;
1177 | <<if ( $not ) warn("~ NONTERMINAL is an undefined operation");>>
1179 <<$$ = buildRuleRef(LATEXT(1));>>
1180 { "!" <<q = (RuleRefNode *) ((Junction *)$$.left)->p1;
1181 q->astnode=ASTexclude;>>
1184 PassAction <<addParm(((Junction *)$$.left)->p1, LATEXT(1));>>
1186 <<rr=(RuleRefNode *) ((Junction *)$$.left)->p1;>>
1191 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1192 require(a!=NULL, "rule element: cannot allocate assignment");
1193 strcpy(a, LATEXT(1));
1198 if ( label!=NULL ) {
1199 rr->el_label = label->str;
1200 label->elem = (Node *)rr;
1202 if ( $first_on_line ) {
1203 CurAltStart = (Junction *)$$.left;
1204 ((RuleRefNode *)((Junction *)$$.left)->p1)->altstart = CurAltStart;
1210 | <<if ( $not ) warn("~ ACTION is an undefined operation");>>
1211 Action <<$0 = buildAction(LATEXT(1),action_file,action_line, 0);>>
1212 <<if ( $first_on_line ) CurAltStart = (Junction *)$0.left;>>
1213 <<$node = (Node *) ((Junction *)$0.left)->p1;>>
1215 | <<if ( $not ) warn("~ SEMANTIC-PREDICATE is an undefined operation");>>
1216 Pred <<$0 = buildAction(LATEXT(1),action_file,action_line, 1);>>
1217 <<act = (ActionNode *) ((Junction *)$0.left)->p1;>>
1221 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1222 require(a!=NULL, "rule element: cannot allocate predicate fail action");
1223 strcpy(a, LATEXT(1));
1227 <<if ( $first_on_line ) CurAltStart = (Junction *)$0.left;>>
1228 <<$node = (Node *)act;>>
1230 | <<if ( $not ) warn("~ BLOCK is an undefined operation");>>
1233 ( "approx" <<approx=LL_k;>>
1234 | "LL(1)" <<approx = 1;>>
1235 | "LL(2)" <<approx = 2;>>
1238 ( "\(" block[&toksrefd,&rulesrefd] "\)"
1239 <<blk = $$ = $2; --BlkLevel;>>
1240 ( "\*" <<$$ = makeLoop($$,approx);>>
1241 | "\+" <<$$ = makePlus($$,approx);>>
1243 ( "=>" Pred /* generalized predicate */
1244 /* first make into a predicate */
1245 <<$$ = buildAction(LATEXT(1),action_file,action_line,1);>>
1246 <<act = (ActionNode *) ((Junction *)$$.left)->p1;>>
1250 a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char));
1251 require(a!=NULL, "rule element: cannot allocate predicate fail action");
1252 strcpy(a, LATEXT(1));
1256 <<if ($first_on_line) CurAltStart=(Junction *)$$.left;>>
1257 <<$node = (Node *)act;>>
1259 /* for now, just snag context */
1261 pred = computePredicateFromContextGuard(blk);
1263 err("invalid or missing context guard");
1265 pred->expr = act->action;
1267 act->guardpred = pred;
1270 | <<$$ = makeBlk($$,approx);
1272 ((Junction *) ((Junction *)$$.left)->p1)->guess=1;
1273 if ( !$first_on_line ) {
1274 err("(...)? predicate must be first element of production");
1278 | <<$$ = makeBlk($$,approx);>>
1282 ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID;
1283 ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd;
1284 ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd;
1285 if ( $first_on_line )
1286 CurAltStart = (Junction *)((Junction *)((Junction *)$$.left)->p1);
1287 $node = (Node *) ((Junction *)$$.left)->p1;
1291 | "\{" block[&toksrefd,&rulesrefd]
1292 <<$$ = makeOpt($2,approx); --BlkLevel;>>
1295 ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID;
1296 ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd;
1297 ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd;
1299 <<if ( $first_on_line )
1300 CurAltStart = (Junction *) ((Junction *)((Junction *)$$.left)->p1);
1302 <<$node = (Node *) ((Junction *)$$.left)->p1;>>
1306 /* Error catching alternatives */
1307 | "\*" <<warn("don't you want a ')' with that '*'?"); CannotContinue=TRUE;>>
1308 | "\+" <<warn("don't you want a ')' with that '+'?"); CannotContinue=TRUE;>>
1309 | "\>" <<warn("'>' can only appear after a nonterminal"); CannotContinue=TRUE;>>
1310 | PassAction <<warn("[...] out of context 'rule > [...]'");
1311 CannotContinue=TRUE;>>
1313 <<CannotContinue=TRUE;>>
1315 default_exception_handler
1316 : exception_group > [DefaultExGroup]
1319 exception_group > [ExceptionGroup *eg]
1320 : <<ExceptionHandler *h; LabelEntry *label=NULL; FoundException = 1;>>
1321 "exception" <<$eg = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));>>
1323 PassAction /* did they attach a label? */
1326 p[strlen(p)-1] = '\0'; /* kill trailing space */
1327 label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1);
1330 err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1));
1334 ( exception_handler > [h]
1335 <<list_add(&($eg->handlers), (void *)h);>>
1337 { "default" ":" Action
1339 ExceptionHandler *eh = (ExceptionHandler *)
1340 calloc(1, sizeof(ExceptionHandler));
1341 char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1342 require(eh!=NULL, "exception: cannot allocate handler");
1343 require(a!=NULL, "exception: cannot allocate action");
1344 strcpy(a, LATEXT(1));
1346 eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char));
1347 require(eh->signalname!=NULL, "exception: cannot allocate sig name");
1348 strcpy(eh->signalname, "default");
1349 list_add(&($eg->handlers), (void *)eh);
1353 if ( label!=NULL ) {
1354 /* Record ex group in sym tab for this label */
1355 if ( label->ex_group!=NULL ) {
1356 err(eMsg1("duplicate exception handler for label '%s'",label->str));
1359 label->ex_group = $eg;
1360 /* Label the exception group itself */
1361 $eg->label = label->str;
1362 /* Make the labelled element pt to the exception also */
1363 switch ( label->elem->ntype ) {
1366 RuleRefNode *r = (RuleRefNode *)label->elem;
1372 TokNode *t = (TokNode *)label->elem;
1378 /* You may want to remove this exc from the rule list
1379 * and handle at the labeled element site.
1385 <<CannotContinue=TRUE;>>
1387 exception_handler > [ExceptionHandler *eh]
1391 $eh = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler));
1392 require($eh!=NULL, "exception: cannot allocate handler");
1396 $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1397 require($eh->signalname!=NULL, "exception: cannot allocate sig name");
1398 strcpy($eh->signalname, LATEXT(1));
1402 $eh->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1403 require($eh->signalname!=NULL, "exception: cannot allocate sig name");
1404 strcpy($eh->signalname, LATEXT(1));
1408 { <<$eh->action = NULL;>>
1411 $eh->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1412 require($eh->action!=NULL, "exception: cannot allocate action");
1413 strcpy($eh->action, LATEXT(1));
1417 <<CannotContinue=TRUE;>>
1419 #token NonTerminal "[a-z] [A-Za-z0-9_]*"
1421 while ( zzchar==' ' || zzchar=='\t' ) {
1424 if ( zzchar == ':' && inAlt ) NLA = LABEL;
1426 #token TokenTerm "[A-Z] [A-Za-z0-9_]*"
1428 while ( zzchar==' ' || zzchar=='\t' ) {
1431 if ( zzchar == ':' && inAlt ) NLA = LABEL;
1433 #token "#[A-Za-z0-9_]*" <<warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip(); >>
1435 #lexclass PARSE_ENUM_FILE
1437 #token "[\t\ ]+" << zzskip(); >> /* Ignore White */
1438 #token "[\n\r]" << zzline++; zzskip(); >> /* Track Line # */
1439 #token "//" << zzmode(TOK_DEF_CPP_COMMENTS); zzmore(); >>
1440 #token "/\*" << zzmode(TOK_DEF_COMMENTS); zzskip(); >>
1441 #token "#ifdef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
1442 #token "#if" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
1443 #token "#ifndef" << ; >>
1444 #token "#else" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
1445 #token "#endif" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
1446 #token "#undef" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
1447 #token "#import" << zzmode(TOK_DEF_CPP_COMMENTS); zzskip(); >>
1450 enum_file[char *fname]
1452 { "#define" ID /* ignore if it smells like a gate */
1453 /* First #define after the first #ifndef (if any) is ignored */
1456 ( ( enum_def[$fname] )+
1462 defines[char *fname]
1463 : <<int v,maxt= -1; char *t;>>
1466 <<t = mystrdup(LATEXT(1));>>
1469 v = atoi(LATEXT(1));
1470 /* fprintf(stderr, "#token %s=%d\n", t, v);*/
1472 if ( v>maxt ) maxt=v;
1473 if ( Tnum( t ) == 0 ) addForcedTname( t, v );
1475 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
1479 <<TokenNum = maxt + 1;>>
1482 enum_def[char *fname]
1483 : <<int v= 0; char *t;>>
1487 <<t = mystrdup(LATEXT(1));>>
1488 ( "=" INT <<v=atoi(LATEXT(1));>>
1492 /* fprintf(stderr, "#token %s=%d\n", t, v);*/
1494 if ( Tnum( t ) == 0 ) addForcedTname( t, v );
1496 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
1501 <<t = mystrdup(LATEXT(1));>>
1502 ( "=" INT <<v=atoi(LATEXT(1));>>
1506 /* fprintf(stderr, "#token %s=%d\n", t, v);*/
1508 if ( Tnum( t ) == 0 ) addForcedTname( t, v );
1510 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
1521 #token ID "[a-zA-Z_][_a-zA-Z0-9]*"
1526 /* semantics of #token */
1529 chkToken(char *t, char *e, char *a, int tnum)
1531 chkToken(t,e,a,tnum)
1538 /* check to see that they don't try to redefine a token as a token class */
1540 p = (TermEntry *) hash_get(Tname, t);
1541 if ( p!=NULL && p->classname ) {
1542 err(eMsg1("redefinition of #tokclass '%s' to #token not allowed; ignored",t));
1543 if ( a!=NULL ) free((char *)a);
1548 if ( t==NULL && e==NULL ) { /* none found */
1549 err("#token requires at least token name or rexpr");
1551 else if ( t!=NULL && e!=NULL ) { /* both found */
1552 if ( UserDefdTokens ) { /* if #tokdefs, must not define new */
1553 p = (TermEntry *) hash_get(Tname, t);
1555 err(eMsg1("#token definition '%s' not allowed with #tokdefs; ignored",t));
1561 if ( hasAction(e) ) {
1562 err(eMsg1("redefinition of action for %s; ignored",e));
1564 else setHasAction(e, a);
1567 else if ( t!=NULL ) { /* only one found */
1568 if ( UserDefdTokens ) {
1569 err(eMsg1("#token definition '%s' not allowed with #tokdefs; ignored",t));
1572 if ( Tnum( t ) == 0 ) addTname( t );
1574 err(eMsg1("redefinition of token %s; ignored",t));
1577 err(eMsg1("action cannot be attached to a token name (%s); ignored",t));
1581 else if ( e!=NULL ) {
1582 if ( Tnum( e ) == 0 ) addTexpr( e );
1584 if ( hasAction(e) ) {
1585 err(eMsg1("redefinition of action for expr %s; ignored",e));
1587 else if ( a==NULL ) {
1588 err(eMsg1("redefinition of expr %s; ignored",e));
1591 if ( a!=NULL ) setHasAction(e, a);
1594 /* if a token type number was specified, then add the token ID and 'tnum'
1595 * pair to the ForcedTokens list. (only applies if an id was given)
1597 if ( t!=NULL && tnum>0 )
1599 if ( set_el(tnum, reserved_positions) )
1601 err(eMsgd("a token has already been forced to token number %d; ignored", tnum));
1605 list_add(&ForcedTokens, newForcedToken(t,tnum));
1606 set_orel(tnum, &reserved_positions);
1615 match_token(char *s, char **nxt)
1622 if ( !(*s>='A' && *s<='Z') ) return 0;
1624 while ( (*s>='a' && *s<='z') ||
1625 (*s>='A' && *s<='Z') ||
1626 (*s>='0' && *s<='9') ||
1631 if ( *s!=' ' && *s!='}' ) return 0;
1638 match_rexpr(char *s, char **nxt)
1645 if ( *s!='"' ) return 0;
1650 warn("eoln found in regular expression");
1651 if ( *s=='\\' ) s++;
1659 * Walk a string "{ A .. Z }" where A..Z is a space separated list
1660 * of token references (either labels or reg exprs). Return a
1661 * string "inlineX_set" for some unique integer X. Basically,
1662 * we pretend as if we had seen "#tokclass inlineX { A .. Z }"
1663 * on the input stream outside of an action.
1674 fprintf(stderr, "found consumeUntil( {...} )\n");
1675 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
1678 err("malformed consumeUntil( {...} ); missing '{'");
1682 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
1685 if ( match_token(s,&nxt) ) fprintf(stderr, "found token %s\n", s);
1686 else if ( match_rexpr(s,&nxt) ) fprintf(stderr, "found rexpr %s\n", s);
1688 err("invalid element in consumeUntil( {...} )");
1692 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
1694 return "inlineX_set";
1699 /* ANTLR-specific syntax error message generator
1700 * (define USER_ZZSYN when compiling so don't get 2 definitions)
1704 zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok,
1705 int k, char *bad_text)
1707 zzsyn(text, tok, egroup, eset, etok, k, bad_text)
1708 char *text, *egroup, *bad_text;
1715 fprintf(stderr, ErrHdr, FileStr[CurFile]!=NULL?FileStr[CurFile]:"stdin", zzline);
1716 fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text);
1717 if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
1718 if ( k==1 ) fprintf(stderr, " missing");
1721 fprintf(stderr, "; \"%s\" not", bad_text);
1722 if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
1724 if ( zzset_deg(eset)>0 ) zzedecode(eset);
1725 else fprintf(stderr, " %s", zztokens[etok]);
1726 if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup);
1727 fprintf(stderr, "\n");