]> pd.if.org Git - pccts/blob - antlr/antlr.g
auto commit for import
[pccts] / antlr / antlr.g
1 /*
2  * antlr.g      --      PCCTS Version 1.xx ANTLR
3  *
4  * $Id: antlr.g,v 1.7 95/10/05 11:57:12 parrt Exp $
5  * $Revision: 1.7 $
6  *
7  * Parse an antlr input grammar and build a syntax-diagram.
8  *
9  * Written in itself (needs at least 1.06 to work)
10  *
11  * SOFTWARE RIGHTS
12  *
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.
18  *
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
29  * completed.
30  *
31  * ANTLR 1.33
32  * Terence Parr
33  * Parr Research Corporation
34  * with Purdue University and AHPCRC, University of Minnesota
35  * 1989-1995
36  */
37 #header <<
38         #ifdef __cplusplus
39         #ifndef __STDC__
40         #define __STDC__
41         #endif
42         #endif
43         #include "set.h"
44         #include <ctype.h>
45         #include "syn.h"
46         #include "hash.h"
47         #include "generic.h"
48         #define zzcr_attr(attr,tok,t)
49         >>
50
51 <<
52 #ifdef __STDC__
53 static void chkToken(char *, char *, char *, int);
54 #else
55 static void chkToken();
56 #endif
57
58 static int class_nest_level = 0;
59 extern int inAlt;
60 extern set attribsRefdFromAction;
61 extern int UsedOldStyleAttrib;
62 extern int UsedNewStyleLabel;
63 >>
64
65 #lexaction <<
66 /* maintained, but not used for now */
67 set AST_nodes_refd_in_actions = set_init;
68 int inAlt = 0;
69 set attribsRefdFromAction;
70 int UsedOldStyleAttrib = 0;
71 int UsedNewStyleLabel = 0;
72 #ifdef __USE_PROTOS
73 char *inline_set(char *);
74 #else
75 char *inline_set();
76 #endif
77 >>
78
79 #lexclass STRINGS
80 #token QuotedTerm "\""          << zzmode(START); >>
81 #token "[\n\r]"                                 <<
82                                                         zzline++;
83                                                         warn("eoln found in string");
84                                                         zzskip();
85                                                         >>
86 #token "\\[\n\r]"                               << zzline++; zzmore(); >>
87 #token "\\~[]"                          << zzmore(); >>
88 #token "~[\n\r\"\\]+"                   << zzmore(); >>
89
90 #lexclass ACTION_STRINGS
91 #token "\""                                     << zzmode(ACTIONS); zzmore(); >>
92 #token "[\n\r]"                         <<
93                                                         zzline++;
94                                                         warn("eoln found in string (in user action)");
95                                                         zzskip();
96                                                         >>
97 #token "\\[\n\r]"                               << zzline++; zzmore(); >>
98 #token "\\~[]"                          << zzmore(); >>
99 #token "~[\n\r\"\\]+"                   << zzmore(); >>
100
101 #lexclass ACTION_CHARS
102 #token "'"                                      << zzmode(ACTIONS); zzmore(); >>
103 #token "[\n\r]"                         <<
104                                                         zzline++;
105                                                         warn("eoln found in char literal (in user action)");
106                                                         zzskip();
107                                                         >>
108 #token "\\~[]"                          << zzmore(); >>
109 #token "~[\n\r'\\]+"                    << zzmore(); >>
110
111 #lexclass ACTION_COMMENTS
112 #token "\*/"                            << zzmode(ACTIONS); zzmore(); >>
113 #token "\*"                                     << zzmore(); >>
114 #token "[\n\r]"                         << zzline++; zzmore(); DAWDLE; >>
115 #token "~[\n\r\*]+"                     << zzmore(); >>
116
117 #lexclass TOK_DEF_COMMENTS
118 #token "\*/"                            << zzmode(PARSE_ENUM_FILE);  
119 zzmore(); >>
120 #token "\*"                                     << zzmore(); >>
121 #token "[\n\r]"                         << zzline++; zzmore(); DAWDLE; >>
122 #token "~[\n\r\*]+"                     << zzmore(); >>
123
124 #lexclass TOK_DEF_CPP_COMMENTS
125 #token "[\n\r]"                         << zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE; >>
126 #token "~[\n\r]+"                               << zzskip(); >>
127
128 #lexclass ACTION_CPP_COMMENTS
129 #token "[\n\r]"                         << zzline++; zzmode(ACTIONS); zzmore(); DAWDLE; >>
130 #token "~[\n\r]+"                       << zzmore(); >>
131
132 #lexclass CPP_COMMENTS
133 #token "[\n\r]"                         << zzline++; zzmode(START); zzskip(); DAWDLE; >>
134 #token "~[\n\r]+"                       << zzskip(); >>
135
136 #lexclass COMMENTS
137 #token "\*/"                            << zzmode(START); zzskip(); >>
138 #token "\*"                                     << zzskip(); >>
139 #token "[\n\r]"                         << zzline++; zzskip(); DAWDLE; >>
140 #token "~[\n\r\*]+"                     << zzskip(); >>
141
142 /*
143  * This lexical class accepts actions of type [..] and <<..>>
144  *
145  * It translates the following special items for C:
146  *
147  * $j           --> "zzaArg(current zztasp, j)"
148  * $i.j         --> "zzaArg(zztaspi, j)"
149  * $i.nondigit> "zzaArg(current zztasp, i).nondigit"
150  * $$           --> "zzaRet"
151  * $alnum       --> "alnum"                     (used to ref parameters)
152  * $rule        --> "zzaRet"
153  * $retval      --> "_retv.retval" if > 1 return values else "_retv"
154  * $[token, text] --> "zzconstr_attr(token, text)"
155  * $[]          --> "zzempty_attr()"
156  *
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.)
160  *
161  * $j           --> "_tbj" where b is the block level
162  * $i.j         --> "_tij"
163  * $j->nondigit> "_tbj->nondigit"
164  * $$           --> "$$"
165  * $alnum       --> "alnum"                     (used to ref parameters)
166  * $rule        --> "$rule"
167  * $retval      --> "_retv.retval" if > 1 return values else "_retv"
168  * $[token, text] --> invalid
169  * $[]          --> invalid
170  *
171  * And, for trees:
172  *
173  * #0           -->     "(*_root)"
174  * #i           --> "zzastArg(i)"
175  * #[args]      --> "zzmk_ast(zzastnew(), args)"
176  * #[]          --> "zzastnew()"
177  * #( root, child1, ..., childn )
178  *                      --> "zztmake(root, child1, ...., childn, NULL)"
179  * #()          --> "NULL"
180  *
181  * For C++, ...
182  *
183  * #0           -->     "(*_root)"
184  * #i           --> "_astbi" where b is the block level
185  * #alnum       --> "alnum_ast" (used to ref #label)
186  * #[args]      --> "new AST(args)"
187  * #[]          --> "new AST"
188  * #( root, child1, ..., childn )
189  *                      --> "AST::tmake(root, child1, ...., childn, NULL)"
190  * #()          --> "NULL"
191  *
192  * To escape,
193  *
194  * \]           --> ]
195  * \)           --> )
196  * \$           --> $
197  * \#           --> #
198  *
199  * A stack is used to nest action terminators because they can be nested
200  * like crazy:  << #[$[..],..] >>
201  */
202 #lexclass ACTIONS
203 #token Action "\>\>"        << /* these do not nest */
204                               zzmode(START);
205                               NLATEXT[0] = ' ';
206                               NLATEXT[1] = ' ';
207                               zzbegexpr[0] = ' ';
208                               zzbegexpr[1] = ' ';
209                                                           if ( zzbufovf ) {
210                                                                 err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
211                                                           }
212                             >>
213 #token Pred "\>\>?"                     << /* these do not nest */
214                               zzmode(START);
215                               NLATEXT[0] = ' ';
216                               NLATEXT[1] = ' ';
217                               zzbegexpr[0] = '\0';
218                                                           if ( zzbufovf ) {
219                                                                 err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE));
220                                                           }
221                             >>
222 #token PassAction "\]"          << if ( topint() == ']' ) {
223                                                                   popint();
224                                                                   if ( istackempty() )  /* terminate action */
225                                                                   {
226                                                                           zzmode(START);
227                                                                           NLATEXT[0] = ' ';
228                                                                           zzbegexpr[0] = ' ';
229                                                                           if ( zzbufovf ) {
230                                                                                 err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
231                                                                           }
232                                                                   }
233                                                                   else {
234                                                                           /* terminate $[..] and #[..] */
235                                                                           if ( GenCC ) zzreplstr("))");
236                                                                           else zzreplstr(")");
237                                                                           zzmore();
238                                                                   }
239                                                            }
240                                                            else if ( topint() == '|' ) { /* end of simple [...] */
241                                                                   popint();
242                                                                   zzmore();
243                                                            }
244                                                            else zzmore();
245                                                         >>
246 #token "consumeUntil\( [\ \t]* \{~[\}]+\} [\ \t]* \)"
247                                                         <<
248                                                         zzmore();
249                                                         zzreplstr(inline_set(zzbegexpr+
250                                                                           strlen("consumeUntil(")));
251                                                         >>
252 #token "consumeUntil\( ~[\)]+ \)"
253                                                         << zzmore(); >>
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"); >>
259
260 #token "$\[\]"                          << if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();}
261                                                            else err("$[] use invalid in C++ mode"); >>
262 #token "$\["                            <<
263                                                         pushint(']');
264                                                         if ( !GenCC ) zzreplstr("zzconstr_attr(");
265                                                         else err("$[..] use invalid in C++ mode");
266                                                         zzmore();
267                                                         >>
268 #token "$[0-9]+"                        <<{
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);
277                                                         zzreplstr(buf);
278                                                         zzmore();
279                                                         UsedOldStyleAttrib = 1;
280                                                         if ( UsedNewStyleLabel )
281                                                                 err("cannot mix old-style $i with new-style labels");
282                                                         }
283                                                         >>
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);
294                                                         zzreplstr(buf);
295                                                         zzmore();
296                                                         UsedOldStyleAttrib = 1;
297                                                         if ( UsedNewStyleLabel )
298                                                                 err("cannot mix old-style $i with new-style labels");
299                                                         }
300                                                         >>
301 #token "$[0-9]+.[0-9]+"         <<{
302                                                         static char buf[100];
303                                                         static char i[20], j[20];
304                                                         char *p,*q;
305                                                         if (strlen(zzbegexpr)>(size_t)85) fatal("$i.j attrib ref too big");
306                                                         for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) {
307                                                                 if ( q == &i[20] )
308                                                                          fatalFL("i of $i.j attrib ref too big",
309                                                                                          FileStr[CurFile], zzline );
310                                                                 *q++ = *p;
311                                                         }
312                                                         *q = '\0';
313                                                         for (p++, q= &j[0]; *p!='\0'; p++) {
314                                                                 if ( q == &j[20] )
315                                                                         fatalFL("j of $i.j attrib ref too big",
316                                                                                         FileStr[CurFile], zzline );
317                                                                 *q++ = *p;
318                                                         }
319                                                         *q = '\0';
320                                                         if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j);
321                                                         else sprintf(buf,"_t%s%s",i,j);
322                                                         zzreplstr(buf);
323                                                         zzmore();
324                                                         UsedOldStyleAttrib = 1;
325                                                         if ( UsedNewStyleLabel )
326                                                                 err("cannot mix old-style $i with new-style labels");
327                                                         }
328                                                         >>
329 #token "$[_a-zA-Z][_a-zA-Z0-9]*"
330                                                         <<{ static char buf[300]; LabelEntry *el;
331                                                         zzbegexpr[0] = ' ';
332                                                         if ( CurRule != NULL &&
333                                                                  strcmp(CurRule, &zzbegexpr[1])==0 ) {
334                                                                 if ( !GenCC ) zzreplstr("zzaRet");
335                                                         }
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]);
342                                                                         zzreplstr(buf);
343                                                                 }
344                                                                 else zzreplstr("_retv");
345                                                         }
346                                                         else if ( CurParmDef != NULL &&
347                                                                           strmember(CurParmDef, &zzbegexpr[1])) {
348                                                                 ;
349                                                         }
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])); }
355                                                         }
356                                                         else
357                                                                 warn(eMsg1("$%s not parameter, return value, or element label",&zzbegexpr[1]));
358                                                         }
359                                                         zzmore();
360                                                         >>
361 #token "#0"                                     << zzreplstr("(*_root)"); zzmore(); chkGTFlag(); >>
362 #token "#\[\]"                          << if ( GenCC ) {zzreplstr("(new AST)");}
363                                                            else {zzreplstr("zzastnew()");} zzmore();
364                                                            chkGTFlag();
365                                                         >>
366 #token "#\(\)"                          << zzreplstr("NULL"); zzmore(); chkGTFlag(); >>
367 #token "#[0-9]+"                        <<{
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);
373                                                         zzreplstr(buf);
374                                                         zzmore();
375                                                         set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions);
376                                                         chkGTFlag();
377                                                         }
378                                                         >>
379 #token "#[_a-zA-Z][_a-zA-Z0-9]*"
380                                                         <<
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) )
393                                                         {
394                                                                 static char buf[100];
395                                                                 sprintf(buf, "%s_ast", zzbegexpr+1);
396                                                                 zzreplstr(buf);
397                                                                 chkGTFlag();
398                                                         }
399                                                         zzmore();
400                                                         >>
401 #token "#\["                            <<
402                                                         pushint(']');
403                                                         if ( GenCC ) zzreplstr("(new AST(");
404                                                         else zzreplstr("zzmk_ast(zzastnew(),");
405                                                         zzmore();
406                                                         chkGTFlag();
407                                                         >>
408 #token "#\("                            <<
409                                                         pushint('}');
410                                                         if ( GenCC ) zzreplstr("ASTBase::tmake(");
411                                                         else zzreplstr("zztmake(");
412                                                         zzmore();
413                                                         chkGTFlag();
414                                                         >>
415 #token "#"                                      << zzmore(); >>
416 #token "\)"                                     <<
417                                                         if ( istackempty() )
418                                                                 zzmore();
419                                                         else if ( topint()==')' ) {
420                                                                 popint();
421                                                         }
422                                                         else if ( topint()=='}' ) {
423                                                                 popint();
424                                                                 /* terminate #(..) */
425                                                                 zzreplstr(", NULL)");
426                                                         }
427                                                         zzmore();
428                                                         >>
429 #token "\["                                     <<
430                                                         pushint('|');   /* look for '|' to terminate simple [...] */
431                                                         zzmore();
432                                                         >>
433 #token "\("                                     <<
434                                                         pushint(')');
435                                                         zzmore();
436                                                         >>
437
438 #token "\\\]"                           << zzreplstr("]");  zzmore(); >>
439 #token "\\\)"                           << zzreplstr(")");  zzmore(); >>
440 #token "\\>"                            << zzreplstr(">");  zzmore(); >>
441
442
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(); >>
454
455 #lexclass START
456 #token "[\t\ ]+"                        << zzskip(); >>                         /* Ignore White */
457 #token "[\n\r]"                         << zzline++; zzskip(); >>       /* Track Line # */
458 #token "\["                 << zzmode(ACTIONS); zzmore();
459                                istackreset();
460                                pushint(']'); >>
461 #token "\<\<"               << action_file=CurFile; action_line=zzline;
462                                zzmode(ACTIONS); zzmore();
463                                istackreset();
464                                pushint('>'); >>
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(); >>
470 #token WildCard "."
471 #token "\@"                                     <<FoundException = 1;>>
472 #token Eof                                      "@"
473                                                         <<      /* L o o k  F o r  A n o t h e r  F i l e */
474                                                         {
475                                                         FILE *new_input;
476                                                         new_input = NextFile();
477                                                         if ( new_input == NULL ) { NLA=Eof; return; }
478                                                         fclose( input );
479                                                         input = new_input;
480                                                         zzrdstream( input );
481                                                         zzskip();       /* Skip the Eof (@) char i.e continue */
482                                                         }
483                                                         >>
484
485 #token LABEL
486
487 #errclass "grammar-element" { element }
488 #errclass "meta-symbol"         { "\}" "!" ";" "\|" "\~" "^" "\)" }
489
490 /*
491  * Get a grammar -- Build a list of rules like:
492  *
493  *      o-->Rule1--o
494  *      |
495  *      o-->Rule2--o
496  *      |
497  *      ...
498  *      |
499  *      o-->RuleN--o
500  */
501 grammar :       <<Graph g;>>
502                         (       "#header" Action
503                                 <<
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));
508                                 }
509                                 else warn("additional #header statement ignored");
510                                 >>
511                         |       "#parser" QuotedTerm
512                                 <<
513                                 if ( GenCC ) {
514                                         warn("#parser meta-op incompatible with -CC; ignored");
515                                 }
516                                 else {
517                                         if ( strcmp(ParserName,"zzparser")==0 ) {
518                                                 ParserName=StripQuotes(mystrdup(LATEXT(1)));
519                                                 if ( RulePrefix[0]!='\0' )
520                                                 {
521                                                         warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored");
522                                                         RulePrefix[0]='\0';
523                                                 }
524                                         }
525                                         else warn("additional #parser statement ignored");
526                                 }
527                                 >>
528                         |       "#tokdefs" QuotedTerm
529                                 <<{
530                                 char *fname;
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));}
538                                 else {
539                                         ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE);
540                                         UserDefdTokens = 1;
541                                 }
542                                 zzrestore_antlr_state(&st);
543                                 zzrestore_dlg_state(&dst);
544                                 }>>
545                         )*
546                         (       Action
547                                 <<{
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);
552                                 }>>
553                         |       laction
554                         |       aLexclass
555                         |       token
556                         |       error
557                         |       tclass
558                         |       default_exception_handler
559                         |       class_def
560                         |       "\}"
561                                 <<
562                                 if ( class_nest_level==0 )
563                                         warn("missing class definition for trailing '}'");
564                                 class_nest_level--;
565                                 >>
566                         )*
567                         rule            <<g=$3; SynDiag = (Junction *) $3.left;>>
568                         (       rule    <<if ( $1.left!=NULL ) {g.right = NULL; g = Or(g, $1);}>>
569                         |       aLexclass
570                         |       token
571                         |       error
572                         |       tclass
573                         |       class_def
574                         |       "\}"
575                                 <<
576                                 if ( class_nest_level==0 )
577                                         warn("missing class definition for trailing '}'");
578                                 class_nest_level--;
579                                 >>
580                         )*
581                         (       Action
582                                 <<{
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);
587                                 }>>
588                         |       laction
589                         |       error
590                         |       tclass
591                         |       class_def
592                         |       "\}"
593                                 <<
594                                 if ( class_nest_level==0 )
595                                         warn("missing class definition for trailing '}'");
596                                 class_nest_level--;
597                                 >>
598                         )*
599                         Eof
600                 ;
601                 <<CannotContinue=TRUE;>>
602
603 class_def
604         :       <<int go=1; char name[MaxRuleName+1];>>
605                 "class"
606                 (       NonTerminal             <<if(go) strncpy(name,LATEXT(1),MaxRuleName);>>
607                 |       TokenTerm               <<if(go) strncpy(name,LATEXT(1),MaxRuleName);>>
608                 )
609                 <<
610                 if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0
611                          && GenCC ) {
612                         err("only one grammar class allowed in this release");
613                         go = 0;
614                 }
615                 else strcpy(CurrentClassName, name);
616                 >>
617                 <<if ( !GenCC ) { err("class meta-op used without C++ option"); }>>
618                 "\{"
619                 <<
620                 no_classes_found = 0;
621                 if ( class_nest_level>=1 ) {warn("cannot have nested classes");}
622                 else class_nest_level++;
623                 >>
624         ;
625         <<CannotContinue=TRUE;>>
626
627 /*
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.
633  *
634  * Note that locks are required on the RuleBlk and EndRule nodes to thwart
635  * infinite recursion.
636  *
637  * Return the left graph pointer == NULL to indicate error/dupl rule def.
638  */
639 rule    :       <<
640                         ListNode *ex_groups = NULL;
641                         ExceptionGroup *eg;
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;
645                         CurExGroups = 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;
651                         >>
652                         NonTerminal
653                         <<q=NULL;
654                           if ( hash_get(Rname, LATEXT(1))!=NULL ) {
655                                   err(eMsg1("duplicate rule definition: '%s'",LATEXT(1)));
656                                   CannotContinue=TRUE;
657                           }
658                           else
659                           {
660                                   q = (RuleEntry *)hash_add(Rname,
661                                                                                         LATEXT(1),
662                                                                                         (Entry *)newRuleEntry(LATEXT(1)));
663                               CurRule = q->str;
664                           }
665                           CurRuleNode = q;
666                           f = CurFile; l = zzline;
667                           NumRules++;
668                         >>
669                         {       "!"  <<if ( q!=NULL ) q->noAST = TRUE;>> }
670                         {       <<;>>
671                                 {"\<"}
672                                 PassAction
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));
676                                         CurParmDef = pdecl;
677                                 >>
678                         }
679                         {       "\>"
680                                 PassAction
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));
684                                         CurRetDef = ret;
685                                 >>
686                         }
687                         { QuotedTerm <<if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1));>> }
688                         <<
689                         if ( GenEClasseForRules && q!=NULL ) {
690                                 e = newECnode;
691                                 require(e!=NULL, "cannot allocate error class node");
692                                 if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);}
693                                 else a = q->egroup;
694                                 if ( Tnum( a ) == 0 )
695                                 {
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));
701                                 }
702                                 else {
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]);
705                                         free((char *)e);
706                                 }
707                         }
708                         >>
709                         <<BlkLevel++;>>
710                         ":" <<inAlt=1;>>
711                         block[&toksrefd, &rulesrefd]
712                         <<r = makeBlk($7,0);
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;
728                           p->jtype = EndRule;
729                           p->lock = makelocks();
730                           p->pred_lock = makelocks();
731                           CurRuleBlk->end = p;
732                           if ( q!=NULL ) q->rulenum = NumRules;
733                           $7 = r;
734                         >>
735                         <<--BlkLevel;>>
736                         ";" <<inAlt=0;>>
737                         {       Action
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;
742                                 >>
743                         }
744                         (       exception_group > [eg]
745                                 <<if ( eg!=NULL ) {
746                                         list_add(&CurExGroups, (void *)eg);
747                                         if ( eg->label=='\0' ) q->has_rule_exception = 1;
748                             }
749                                 >>
750                         )*
751                         <<if ( q==NULL ) $0.left = NULL; else $0 = $7;>>
752                         <<CurRuleNode = NULL;>>
753                         <<CurRuleBlk->exceptions = CurExGroups;>>
754                         <<CurRuleBlk->el_labels = CurElementLabels;>>
755                 ;
756                 <<CannotContinue=TRUE;>>
757
758 /*
759 pragma  :       "#pragma" "dup\-labeled\-tokens"
760                         <<Pragma_DupLabeledTokens=1;>>
761                 ;
762 */
763
764 laction :       <<char *a;>>
765                         "#lexaction"
766                         Action
767                         <<
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);
772                         >>
773                 ;
774                 <<CannotContinue=TRUE;>>
775
776 aLexclass:      "#lexclass" TokenTerm <<lexclass(mystrdup(LATEXT(1)));>>
777                 ;
778                 <<CannotContinue=TRUE;>>
779
780 error   :       <<char *t=NULL; ECnode *e; int go=1; TermEntry *p;>>
781                         "#errclass"
782                         (<<;>>  TokenTerm  <<t=mystrdup(LATEXT(1));>>
783                         |               QuotedTerm <<t=mystrdup(LATEXT(1));>>
784                         )
785                         <<e = newECnode;
786                           require(e!=NULL, "cannot allocate error class node");
787                           e->lexclass = CurrentLexClass;
788                           if ( Tnum( (t=StripQuotes(t)) ) == 0 )
789                           {
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);
798                           }
799                           else
800                           {
801                                 warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t));
802                                 free( (char *)e );
803                                 go=0;
804                           }
805                         >>
806                         "\{"
807                                 ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>>
808                                 | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
809                                 | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
810                                 )
811                                 <<if ( go ) list_add(&(e->elist), t);>>
812                                 (
813                                         ( NonTerminal <<if ( go ) t=mystrdup(LATEXT(1));>>
814                                         | TokenTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
815                                         | QuotedTerm <<if ( go ) t=mystrdup(LATEXT(1));>>
816                                         )
817                                         <<if ( go ) list_add(&(e->elist), t);>>
818                                 )*
819                         "\}"
820                 ;
821                 <<CannotContinue=TRUE;>>
822
823 tclass  :       <<char *t=NULL; TCnode *e; int go=1,tok; TermEntry *p, *term;>>
824                         "#tokclass" TokenTerm <<t=mystrdup(LATEXT(1));>>
825                         <<e = newTCnode;
826                           require(e!=NULL, "cannot allocate token class node");
827                           e->lexclass = CurrentLexClass;
828                           if ( Tnum( t ) == 0 )
829                           {
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);
838                           }
839                           else
840                           {
841                                 warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t));
842                                 free( (char *)e );
843                                 go=0;
844                           }
845                         >>
846                         "\{"
847                                 (
848                                 ( TokenTerm
849                                   <<if ( go ) {
850                                         term = (TermEntry *) hash_get(Tname, LATEXT(1));
851                                         if ( term==NULL && UserDefdTokens ) {
852                                                 err("implicit token definition not allowed with #tokdefs");
853                                                 go = 0;
854                                         }
855                                         else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));}
856                                         }>>
857                                 | QuotedTerm
858                                   <<if ( go ) {
859                                         term = (TermEntry *) hash_get(Texpr, LATEXT(1));
860                                         if ( term==NULL && UserDefdTokens ) {
861                                                 err("implicit token definition not allowed with #tokdefs");
862                                                 go = 0;
863                                         }
864                                         else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));}
865                                         }>>
866                                 )
867                                 <<if ( go ) list_add(&(e->tlist), t);>>
868                                 )*
869                         "\}"
870                 ;
871                 <<CannotContinue=TRUE;>>
872
873 token   :       <<char *t=NULL, *e=NULL, *a=NULL; int tnum=0;>>
874                         "#token"
875                         {       TokenTerm  <<t=mystrdup(LATEXT(1));>>
876                                 {       "=" "[0-9]+"            /* define the token type number */
877                                         <<tnum = atoi(LATEXT(1));>>
878                                 }
879                         }
880                         { QuotedTerm <<e=mystrdup(LATEXT(1));>> }
881                         {       Action
882                                 <<
883                                         a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
884                                         require(a!=NULL, "rule token: cannot allocate action");
885                                         strcpy(a, LATEXT(1));
886                                 >>
887                         }
888                         <<chkToken(t, e, a, tnum);>>
889                 ;
890                 <<CannotContinue=TRUE;>>
891
892 block[set *toksrefd, set *rulesrefd]
893                 :       <<
894                         Graph g, b;
895                         set saveblah;
896                         int saveinalt = inAlt;
897                         ExceptionGroup *eg;
898                         *$toksrefd = empty;
899                         *$rulesrefd = empty;
900                         set_clr(AST_nodes_refd_in_actions);
901                         CurBlockID++;
902                         CurAltNum = 1;
903                         saveblah = attribsRefdFromAction;
904                         attribsRefdFromAction = empty;
905                         >>
906                         alt[toksrefd,rulesrefd]         <<b = g = $1;>>
907                         <<
908                         if ( ((Junction *)g.left)->p1->ntype == nAction )
909                         {
910                                 if ( !((ActionNode *)(((Junction *)g.left)->p1))->is_predicate )
911                                 {
912                                         ((ActionNode *)(((Junction *)g.left)->p1))->init_action = TRUE;
913                                 }
914                         }
915                         ((Junction *)g.left)->blockid = CurBlockID;
916                         >>
917
918                         (       exception_group > [eg]
919                                 <<
920                                 if ( eg!=NULL ) {
921                                         eg->altID = makeAltID(CurBlockID,CurAltNum);
922                                         CurAltStart->exception_label = eg->altID;
923                                         list_add(&CurExGroups, (void *)eg);
924                                 }
925                                 >>
926                         )*
927                         <<CurAltNum++;>>
928
929                         (       "\|" <<inAlt=1;>>
930                                 alt[toksrefd,rulesrefd]         <<g = Or(g, $2);>>
931                                 <<
932                                 ((Junction *)g.left)->blockid = CurBlockID;
933                                 >>
934
935                                 (       exception_group > [eg]
936                                         <<
937                                         if ( eg!=NULL ) {
938                                                 eg->altID = makeAltID(CurBlockID,CurAltNum);
939                                                 CurAltStart->exception_label = eg->altID;
940                                                 list_add(&CurExGroups, (void *)eg);
941                                         }
942                                         >>
943                                 )*
944
945                                 <<CurAltNum++;>>
946
947                         )*
948                         <<$0 = b;>>
949                         <<attribsRefdFromAction = saveblah; inAlt = saveinalt;>>
950                 ;
951                 <<CannotContinue=TRUE;>>
952
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;
957                         CurAltStart = NULL;
958                         elems = empty;
959                         inAlt = 1;
960                         >>
961                         {       "\@"    /* handle MismatchedToken signals with default handler */
962                                 <<use_def_MT_handler = 1;>>
963                         }
964                         (       <<int tok;>>
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;>>
968                                 <<
969                                 if ( $2.left!=NULL ) {
970                                         g = Cat(g, $2);
971                                         n++;
972                                         if ( node!=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;
977                                                         tk->elnum = e_num;
978                                                         set_orel(e_num, &elems);
979                                                 }
980                                                 else if ( node->ntype==nRuleRef ) {
981                                                         RuleRefNode *rn = (RuleRefNode *)((Junction *)$2.left)->p1;
982                                                         rn->elnum = e_num;
983                                                         set_orel(e_num, $rulesrefd);
984                                                 }
985                                         }
986                                 }
987                                 >>
988                         )*
989                         <<if ( n == 0 ) g = emptyAlt();
990                           $0 = g;
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++
996                            */
997                           if ( GenCC && !GenAST )
998                           {
999                                   /* This now free's the temp set -ATG 5/6/95 */
1000                                   set temp;
1001                                   temp = set_and(elems, attribsRefdFromAction);
1002                                   set_orin($toksrefd, temp);
1003                                   set_free(temp);
1004                           }
1005                           else set_orin($toksrefd, elems);
1006                           if ( GenCC ) {
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");
1010                                 set_free(dif);
1011                           }
1012                           set_free(elems);
1013                           set_free(attribsRefdFromAction);
1014                           inAlt = 0;
1015                         >>
1016                 ;
1017                 <<CannotContinue=TRUE;>>
1018
1019 element_label > [LabelEntry *label]
1020         :       <<TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;>>
1021                 LABEL   <<lab = mystrdup(LATEXT(1));>>
1022                 <<
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);
1028                 if ( t!=NULL ) {
1029                         err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab));
1030                         $label = NULL;
1031                 }
1032                 else if ( r!=NULL ) {
1033                         err(eMsg1("label definition clashes with rule definition: '%s'", lab));
1034                         $label = NULL;
1035                 }
1036                 else {
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,
1041                                                                                    lab,
1042                                                                                    (Entry *)newLabelEntry(lab));
1043                                 /* add to list of element labels for this rule */
1044                                 list_add(&CurElementLabels, (void *)lab);
1045                                 $label = l;
1046                         }
1047                         else {
1048                                 err(eMsg1("label definitions must be unique per rule: '%s'", lab));
1049                                 $label = NULL;
1050                         }
1051                 }
1052                 >>
1053                 ":"
1054         ;
1055
1056 element[int not, int first_on_line, int use_def_MT_handler] > [Node *node]
1057                 : <<
1058                   Attrib blk;
1059                   Predicate *pred = NULL;
1060                   int local_use_def_MT_handler=0;
1061                   ActionNode *act;
1062                   RuleRefNode *rr;
1063                   set toksrefd, rulesrefd;
1064                   TermEntry *term;
1065                   TokNode *p=NULL; RuleRefNode *q; int approx=0;
1066                   LabelEntry *label=NULL;
1067                   $node = NULL;
1068                   >>
1069                   {element_label>[label]}
1070                   ( TokenTerm
1071                         <<
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;
1076                         }
1077                         else {
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;
1087                                 }
1088                         }
1089                         >>
1090                         {       ".."
1091                                 (       QuotedTerm
1092                                         <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1093                                 |       TokenTerm
1094                                         <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1095                                 )
1096                         }
1097                         <<
1098                         if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) )
1099                                 list_add(&MetaTokenNodes, (void *)p);
1100                         >>
1101                         (       "^"     <<if ( p!=NULL ) p->astnode=ASTroot;>>
1102                         |               <<if ( p!=NULL ) p->astnode=ASTchild;>>
1103                         |       "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>>
1104                         )
1105                         { "\@" <<local_use_def_MT_handler = 1;>> }
1106                         <<
1107                         if ( p!=NULL && $first_on_line ) {
1108                                 CurAltStart = (Junction *)$$.left;
1109                                 p->altstart = CurAltStart;
1110                         }
1111                         if ( p!=NULL )
1112                                 p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler;
1113                         $node = (Node *)p;
1114                         >>
1115                   | QuotedTerm
1116                         <<
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;
1121                         }
1122                         else {
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;
1128                                 }
1129                         }
1130                         >>
1131                         {       ".."
1132                                 (       QuotedTerm
1133                                         <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1134                                 |       TokenTerm
1135                                         <<if ( p!=NULL ) setUpperRange(p, LATEXT(1));>>
1136                                 )
1137                         }
1138                         (       "^"     <<if ( p!=NULL ) p->astnode=ASTroot;>>
1139                         |               <<if ( p!=NULL ) p->astnode=ASTchild;>>
1140                         |       "!" <<if ( p!=NULL ) p->astnode=ASTexclude;>>
1141                         )
1142                         { "\@" <<local_use_def_MT_handler = 1;>> }
1143                         <<
1144                         if ( p!=NULL && (p->upper_range!=0 || p->tclass || $not) )
1145                                 list_add(&MetaTokenNodes, (void *)p);
1146                         >>
1147                         <<
1148                         if ( $first_on_line ) {
1149                                 CurAltStart = (Junction *)$$.left;
1150                                 p->altstart = CurAltStart;
1151                         }
1152                         if ( p!=NULL )
1153                                 p->use_def_MT_handler = $use_def_MT_handler || local_use_def_MT_handler;
1154                         $node = (Node *)p;
1155                         >>
1156
1157                   | <<if ( $not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')");>>
1158                         "."
1159                         <<$$ = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)$$.left)->p1);>>
1160                         (       "^"     <<p->astnode=ASTroot;>>
1161                         |               <<p->astnode=ASTchild;>>
1162                         |       "!" <<p->astnode=ASTexclude;>>
1163                         )
1164                         <<list_add(&MetaTokenNodes, (void *)p);>>
1165                         <<
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;
1172                                 }
1173                         }
1174                         $node = (Node *)p;
1175                         >>
1176
1177                   | <<if ( $not ) warn("~ NONTERMINAL is an undefined operation");>>
1178                         NonTerminal
1179                         <<$$ = buildRuleRef(LATEXT(1));>>
1180                         { "!" <<q = (RuleRefNode *) ((Junction *)$$.left)->p1;
1181                                         q->astnode=ASTexclude;>>
1182                         }
1183                         {       {"\<"}
1184                                 PassAction <<addParm(((Junction *)$$.left)->p1, LATEXT(1));>>
1185                         }
1186                         <<rr=(RuleRefNode *) ((Junction *)$$.left)->p1;>>
1187                         {       <<char *a;>>
1188                                 "\>"
1189                                 PassAction
1190                                 <<
1191                                         a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1192                                         require(a!=NULL, "rule element: cannot allocate assignment");
1193                                         strcpy(a, LATEXT(1));
1194                                         rr->assign = a;
1195                                 >>
1196                         }
1197                         <<
1198                         if ( label!=NULL ) {
1199                                 rr->el_label = label->str;
1200                                 label->elem = (Node *)rr;
1201                         }
1202                         if ( $first_on_line ) {
1203                                 CurAltStart = (Junction *)$$.left;
1204                                 ((RuleRefNode *)((Junction *)$$.left)->p1)->altstart = CurAltStart;
1205                         }
1206                         $node = (Node *)rr;
1207                         >>
1208                   )
1209
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;>>
1214
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;>>
1218                         {       <<char *a;>>
1219                                 PassAction
1220                                 <<
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));
1224                                 act->pred_fail = a;
1225                                 >>
1226                         }
1227                         <<if ( $first_on_line ) CurAltStart = (Junction *)$0.left;>>
1228                         <<$node = (Node *)act;>>
1229
1230                 |       <<if ( $not )   warn("~ BLOCK is an undefined operation");>>
1231                         <<BlkLevel++;>>
1232                         {       "#pragma"
1233                                 (       "approx" <<approx=LL_k;>>
1234                                 |       "LL(1)"  <<approx = 1;>>
1235                                 |       "LL(2)"  <<approx = 2;>>
1236                                 )
1237                         }
1238                         (       "\(" block[&toksrefd,&rulesrefd] "\)"
1239                                 <<blk = $$ = $2; --BlkLevel;>>
1240                                 (       "\*"            <<$$ = makeLoop($$,approx);>>
1241                                 |       "\+"            <<$$ = makePlus($$,approx);>>
1242                                 |       "?"
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;>>
1247                                                 {       <<char *a;>>
1248                                                         PassAction
1249                                                         <<
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));
1253                                                         act->pred_fail = a;
1254                                                         >>
1255                                                 }
1256                                                 <<if ($first_on_line) CurAltStart=(Junction *)$$.left;>>
1257                                                 <<$node = (Node *)act;>>
1258
1259                                                 /* for now, just snag context */
1260                                                 <<
1261                                                 pred = computePredicateFromContextGuard(blk);
1262                                                 if ( pred==NULL )
1263                                                         err("invalid or missing context guard");
1264                                                 else {
1265                                                         pred->expr = act->action;
1266                                                         pred->source = act;
1267                                                         act->guardpred = pred;
1268                                                 }
1269                                                 >>
1270                                         |       <<$$ = makeBlk($$,approx);
1271                                                   FoundGuessBlk = 1;
1272                                                   ((Junction *) ((Junction *)$$.left)->p1)->guess=1;
1273                                                   if ( !$first_on_line ) {
1274                                                         err("(...)? predicate must be first element of production");
1275                                                   }
1276                                                 >>
1277                                         )
1278                                 |       <<$$ = makeBlk($$,approx);>>
1279                                 )
1280                                 <<
1281                                 if ( pred==NULL ) {
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;
1288                                 }
1289                                 >>
1290
1291                         |       "\{"    block[&toksrefd,&rulesrefd]
1292                                                 <<$$ = makeOpt($2,approx); --BlkLevel;>>
1293                                 "\}"
1294                                 <<
1295                                 ((Junction *)((Junction *)$$.left)->p1)->blockid = CurBlockID;
1296                                 ((Junction *)((Junction *)$$.left)->p1)->tokrefs = toksrefd;
1297                                 ((Junction *)((Junction *)$$.left)->p1)->rulerefs = rulesrefd;
1298                                 >>
1299                                 <<if ( $first_on_line )
1300                                         CurAltStart = (Junction *) ((Junction *)((Junction *)$$.left)->p1);
1301                                 >>
1302                                 <<$node = (Node *) ((Junction *)$$.left)->p1;>>
1303
1304                         )
1305
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;>>
1312                 ;
1313                 <<CannotContinue=TRUE;>>
1314
1315 default_exception_handler
1316         :       exception_group > [DefaultExGroup]
1317         ;
1318
1319 exception_group > [ExceptionGroup *eg]
1320         :       <<ExceptionHandler *h; LabelEntry *label=NULL; FoundException = 1;>>
1321                 "exception"      <<$eg = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));>>
1322                 {       <<char *p;>>
1323                         PassAction              /* did they attach a label? */
1324                         <<
1325                         p = LATEXT(1)+1;
1326                         p[strlen(p)-1] = '\0';          /* kill trailing space */
1327                         label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1);
1328                         if ( label==NULL )
1329                         {
1330                                 err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1));
1331                         }
1332                         >>
1333                 }
1334                 (       exception_handler > [h]
1335                         <<list_add(&($eg->handlers), (void *)h);>>
1336                 )*
1337                 {       "default" ":" Action
1338                         <<{
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));
1345                         eh->action = a;
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);
1350                         }>>
1351                 }
1352                 <<
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));
1357                         }
1358                         else {
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 ) {
1364                                         case nRuleRef :
1365                                                 {
1366                                                 RuleRefNode *r = (RuleRefNode *)label->elem;
1367                                                 r->ex_group = $eg;
1368                                                 break;
1369                                                 }
1370                                         case nToken :
1371                                                 {
1372                                                 TokNode *t = (TokNode *)label->elem;
1373                                                 t->ex_group = $eg;
1374                                                 break;
1375                                                 }
1376                                 }
1377                         }
1378                         /* You may want to remove this exc from the rule list
1379                          * and handle at the labeled element site.
1380                          */
1381                         $eg = NULL;
1382                 }
1383                 >>
1384         ;
1385         <<CannotContinue=TRUE;>>
1386
1387 exception_handler > [ExceptionHandler *eh]
1388         :       <<char *a;>>
1389                 "catch"
1390                 <<
1391                 $eh = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler));
1392                 require($eh!=NULL, "exception: cannot allocate handler");
1393                 >>
1394                 (       NonTerminal
1395                         <<
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));
1399                         >>
1400                 |       TokenTerm
1401                         <<
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));
1405                         >>
1406                 )
1407                 ":"
1408                 {       <<$eh->action = NULL;>>
1409                         Action
1410                         <<
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));
1414                         >>
1415                 }
1416         ;
1417         <<CannotContinue=TRUE;>>
1418
1419 #token NonTerminal              "[a-z] [A-Za-z0-9_]*"
1420                                                         <<
1421                                                         while ( zzchar==' ' || zzchar=='\t' ) {
1422                                                                 zzadvance();
1423                                                         }
1424                                                         if ( zzchar == ':' && inAlt ) NLA = LABEL;
1425                                                         >>
1426 #token TokenTerm                "[A-Z] [A-Za-z0-9_]*"
1427                                                         <<
1428                                                         while ( zzchar==' ' || zzchar=='\t' ) {
1429                                                                 zzadvance();
1430                                                         }
1431                                                         if ( zzchar == ':' && inAlt ) NLA = LABEL;
1432                                                         >>
1433 #token "#[A-Za-z0-9_]*" <<warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip(); >>
1434
1435 #lexclass PARSE_ENUM_FILE
1436
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(); >>
1448 #token "@"                                      << ; >>
1449
1450 enum_file[char *fname]
1451         :       {       "#ifndef" ID
1452                         {       "#define" ID /* ignore if it smells like a gate */
1453                                 /* First #define after the first #ifndef (if any) is ignored */
1454                         }
1455                 }
1456                 (       ( enum_def[$fname] )+
1457                 |       defines[$fname]
1458                 )
1459         |
1460         ;
1461
1462 defines[char *fname]
1463         :       <<int v,maxt= -1; char *t;>>
1464                 (
1465                         "#define" ID
1466                         <<t = mystrdup(LATEXT(1));>>
1467                         INT
1468                         <<
1469                         v = atoi(LATEXT(1));
1470 /*                      fprintf(stderr, "#token %s=%d\n", t, v);*/
1471                         TokenNum = v;
1472                         if ( v>maxt ) maxt=v;
1473                         if ( Tnum( t ) == 0 ) addForcedTname( t, v );
1474                         else {
1475                                 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
1476                         }
1477                         >>
1478                 )+
1479                 <<TokenNum = maxt + 1;>>
1480         ;
1481
1482 enum_def[char *fname]
1483         :       <<int v= 0; char *t;>>
1484                 "enum" ID
1485                 "\{"
1486                         ID
1487                         <<t = mystrdup(LATEXT(1));>>
1488                         (       "=" INT <<v=atoi(LATEXT(1));>>
1489                         |                       <<v++;>>
1490                         )
1491                         <<
1492 /*                      fprintf(stderr, "#token %s=%d\n", t, v);*/
1493                         TokenNum = v;
1494                         if ( Tnum( t ) == 0 ) addForcedTname( t, v );
1495                         else {
1496                                 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
1497                         }
1498                         >>
1499                         (       ","
1500                                 {       ID
1501                                         <<t = mystrdup(LATEXT(1));>>
1502                                         (       "=" INT <<v=atoi(LATEXT(1));>>
1503                                         |                       <<v++;>>
1504                                         )
1505                                         <<
1506 /*                                      fprintf(stderr, "#token %s=%d\n", t, v);*/
1507                                         TokenNum = v;
1508                                         if ( Tnum( t ) == 0 ) addForcedTname( t, v );
1509                                         else {
1510                                                 warnFL(eMsg1("redefinition of token %s; ignored",t),$fname,zzline);
1511                                         }
1512                                         >>
1513                                 }
1514                         )*
1515                 "\}"
1516                 ";"
1517                 <<TokenNum++;>>
1518         ;
1519
1520 #token INT      "[0-9]+"
1521 #token ID       "[a-zA-Z_][_a-zA-Z0-9]*"
1522
1523 #lexclass START
1524
1525 <<
1526 /* semantics of #token */
1527 static void
1528 #ifdef __STDC__
1529 chkToken(char *t, char *e, char *a, int tnum)
1530 #else
1531 chkToken(t,e,a,tnum)
1532 char *t, *e, *a;
1533 int tnum;
1534 #endif
1535 {
1536         TermEntry *p;
1537
1538         /* check to see that they don't try to redefine a token as a token class */
1539         if ( t!=NULL ) {
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);
1544                         return;
1545                 }
1546         }
1547
1548         if ( t==NULL && e==NULL ) {                     /* none found */
1549                 err("#token requires at least token name or rexpr");
1550         }
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);
1554                         if ( p==NULL ) {
1555                                 err(eMsg1("#token definition '%s' not allowed with #tokdefs; ignored",t));
1556                                 return;
1557                         }
1558                 }
1559                 Tklink(t, e);
1560                 if ( a!=NULL ) {
1561                         if ( hasAction(e) ) {
1562                                 err(eMsg1("redefinition of action for %s; ignored",e));
1563                         }
1564                         else setHasAction(e, a);
1565                 }
1566         }
1567         else if ( t!=NULL ) {                           /* only one found */
1568                 if ( UserDefdTokens ) {
1569                         err(eMsg1("#token definition '%s' not allowed with #tokdefs; ignored",t));
1570                         return;
1571                 }
1572                 if ( Tnum( t ) == 0 ) addTname( t );
1573                 else {
1574                         err(eMsg1("redefinition of token %s; ignored",t));
1575                 }
1576                 if ( a!=NULL ) {
1577                         err(eMsg1("action cannot be attached to a token name (%s); ignored",t));
1578                         free((char *)a);
1579                 }
1580         }
1581         else if ( e!=NULL ) {
1582                 if ( Tnum( e ) == 0 ) addTexpr( e );
1583                 else {
1584                         if ( hasAction(e) ) {
1585                                 err(eMsg1("redefinition of action for expr %s; ignored",e));
1586                         }
1587                         else if ( a==NULL ) {
1588                                 err(eMsg1("redefinition of expr %s; ignored",e));
1589                         }
1590                 }
1591                 if ( a!=NULL ) setHasAction(e, a);
1592         }
1593
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)
1596          */
1597         if ( t!=NULL && tnum>0 )
1598         {
1599                 if ( set_el(tnum, reserved_positions) )
1600                 {
1601                         err(eMsgd("a token has already been forced to token number %d; ignored", tnum));
1602                 }
1603                 else
1604                 {
1605                         list_add(&ForcedTokens, newForcedToken(t,tnum));
1606                         set_orel(tnum, &reserved_positions);
1607                 }
1608         }
1609 }
1610 >>
1611
1612 <<
1613 static int
1614 #ifdef __USE_PROTOS
1615 match_token(char *s, char **nxt)
1616 #else
1617 match_token(s,nxt)
1618 char *s;
1619 char **nxt;
1620 #endif
1621 {
1622     if ( !(*s>='A' && *s<='Z') ) return 0;
1623         s++;
1624     while ( (*s>='a' && *s<='z') ||
1625                     (*s>='A' && *s<='Z') ||
1626                     (*s>='0' && *s<='9') ||
1627                     *s=='_' )
1628     {
1629            s++;
1630         }
1631         if ( *s!=' ' && *s!='}' ) return 0;
1632         *nxt = s;
1633         return 1;
1634 }
1635
1636 static int
1637 #ifdef __USE_PROTOS
1638 match_rexpr(char *s, char **nxt)
1639 #else
1640 match_rexpr(s,nxt)
1641 char *s;
1642 char **nxt;
1643 #endif
1644 {
1645     if ( *s!='"' ) return 0;
1646         s++;
1647     while ( *s!='"' )
1648     {
1649            if ( *s=='\n' )
1650                   warn("eoln found in regular expression");
1651            if ( *s=='\\' ) s++;
1652            s++;
1653         }
1654         *nxt = s+1;
1655         return 1;
1656 }
1657
1658 /*
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.
1664  */
1665 char *
1666 #ifdef __USE_PROTOS
1667 inline_set(char *s)
1668 #else
1669 inline_set(s)
1670 char *s;
1671 #endif
1672 {
1673         char *nxt;
1674     fprintf(stderr, "found consumeUntil( {...} )\n");
1675         while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
1676         if ( *s!='{' )
1677         {
1678            err("malformed consumeUntil( {...} ); missing '{'");
1679            return "bad_set";
1680         }
1681         s++;
1682         while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
1683         while ( *s!='}' )
1684         {
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);
1687                 else {
1688                     err("invalid element in consumeUntil( {...} )");
1689                         return "bad_set";
1690                 }
1691                 s = nxt;
1692                 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
1693         }
1694         return "inlineX_set";
1695 }
1696 >>
1697
1698 <<
1699 /* ANTLR-specific syntax error message generator
1700  * (define USER_ZZSYN when compiling so don't get 2 definitions)
1701  */
1702 void
1703 #ifdef __STDC__
1704 zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok,  
1705 int k, char *bad_text)
1706 #else
1707 zzsyn(text, tok, egroup, eset, etok, k, bad_text)
1708 char *text, *egroup, *bad_text;
1709 int tok;
1710 int etok;
1711 int k;
1712 SetWordType *eset;
1713 #endif
1714 {
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");
1719         else
1720         {
1721                 fprintf(stderr, "; \"%s\" not", bad_text);
1722                 if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
1723         }
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");
1728 }
1729 >>