]> pd.if.org Git - pccts/blob - antlr/antlr.c
auto commit for import
[pccts] / antlr / antlr.c
1 /*
2  * A n t l r  T r a n s l a t i o n  H e a d e r
3  *
4  * Terence Parr, Will Cohen, and Hank Dietz: 1989-1994
5  * Purdue University Electrical Engineering
6  * With AHPCRC, University of Minnesota
7  * ANTLR Version 1.32
8  */
9 #include <stdio.h>
10 #define ANTLR_VERSION   132
11
12 #ifdef __cplusplus
13 #ifndef __STDC__
14 #define __STDC__
15 #endif
16 #endif
17 #include "set.h"
18 #include <ctype.h>
19 #include "syn.h"
20 #include "hash.h"
21 #include "generic.h"
22 #define zzcr_attr(attr,tok,t)
23 #define zzSET_SIZE 20
24 #include "antlr.h"
25 #include "tokens.h"
26 #include "dlgdef.h"
27 #include "mode.h"
28 #ifndef PURIFY
29 #define PURIFY(r,s)
30 #endif
31 ANTLR_INFO
32
33 #ifdef __STDC__
34 static void chkToken(char *, char *, char *, int);
35 #else
36 static void chkToken();
37 #endif
38
39 static int class_nest_level = 0;
40 extern int inAlt;
41 extern set attribsRefdFromAction;
42 extern int UsedOldStyleAttrib;
43 extern int UsedNewStyleLabel;
44
45 void
46 #ifdef __STDC__
47 grammar(void)
48 #else
49 grammar()
50 #endif
51 {
52         zzRULE;
53         zzBLOCK(zztasp1);
54         zzMake0;
55         {
56         Graph g;  
57         {
58                 zzBLOCK(zztasp2);
59                 zzMake0;
60                 {
61                 while ( 1 ) {
62                         if ( !((setwd1[LA(1)]&0x1))) break;
63                         if ( (LA(1)==88) ) {
64                                 zzmatch(88); zzCONSUME;
65                                 zzmatch(Action);
66                                 
67                                 if ( HdrAction==NULL ) {
68                                         HdrAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
69                                         require(HdrAction!=NULL, "rule grammar: cannot allocate header action");
70                                         strcpy(HdrAction, LATEXT(1));
71                                 }
72                                 else warn("additional #header statement ignored");
73  zzCONSUME;
74
75                         }
76                         else {
77                                 if ( (LA(1)==89) ) {
78                                         zzmatch(89); zzCONSUME;
79                                         zzmatch(QuotedTerm);
80                                         
81                                         if ( GenCC ) {
82                                                 warn("#parser meta-op incompatible with -CC; ignored");
83                                         }
84                                         else {
85                                                 if ( strcmp(ParserName,"zzparser")==0 ) {
86                                                         ParserName=StripQuotes(mystrdup(LATEXT(1)));
87                                                         if ( RulePrefix[0]!='\0' )
88                                                         {
89                                                                 warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored");
90                                                                 RulePrefix[0]='\0';
91                                                         }
92                                                 }
93                                                 else warn("additional #parser statement ignored");
94                                         }
95  zzCONSUME;
96
97                                 }
98                                 else {
99                                         if ( (LA(1)==90) ) {
100                                                 zzmatch(90); zzCONSUME;
101                                                 zzmatch(QuotedTerm);
102                                                 {
103                                                         char *fname;
104                                                         zzantlr_state st; FILE *f; struct zzdlg_state dst;
105                                                         UserTokenDefsFile = mystrdup(LATEXT(1));
106                                                         zzsave_antlr_state(&st);
107                                                         zzsave_dlg_state(&dst);
108                                                         fname = mystrdup(LATEXT(1));
109                                                         f = fopen(StripQuotes(fname), "r");
110                                                         if ( f==NULL ) {warn(eMsg1("cannot open token defs file '%s'", fname+1));}
111                                                         else {
112                                                                 ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE);
113                                                                 UserDefdTokens = 1;
114                                                         }
115                                                         zzrestore_antlr_state(&st);
116                                                         zzrestore_dlg_state(&dst);
117                                                 }  
118  zzCONSUME;
119
120                                         }
121                                 }
122                         }
123                         zzLOOP(zztasp2);
124                 }
125                 zzEXIT(zztasp2);
126                 }
127         }
128         {
129                 zzBLOCK(zztasp2);
130                 zzMake0;
131                 {
132                 while ( 1 ) {
133                         if ( !((setwd1[LA(1)]&0x2))) break;
134                         if ( (LA(1)==Action) ) {
135                                 zzmatch(Action);
136                                 {
137                                         UserAction *ua = newUserAction(LATEXT(1));
138                                         ua->file = action_file; ua->line = action_line;
139                                         if ( class_nest_level>0 ) list_add(&class_before_actions, ua);
140                                         else list_add(&BeforeActions, ua);
141                                 }  
142  zzCONSUME;
143
144                         }
145                         else {
146                                 if ( (LA(1)==101) ) {
147                                         laction();
148                                 }
149                                 else {
150                                         if ( (LA(1)==102) ) {
151                                                 aLexclass();
152                                         }
153                                         else {
154                                                 if ( (LA(1)==105) ) {
155                                                         token();
156                                                 }
157                                                 else {
158                                                         if ( (LA(1)==103) ) {
159                                                                 error();
160                                                         }
161                                                         else {
162                                                                 if ( (LA(1)==104) ) {
163                                                                         tclass();
164                                                                 }
165                                                                 else {
166                                                                         if ( (LA(1)==122) ) {
167                                                                                 default_exception_handler();
168                                                                         }
169                                                                         else {
170                                                                                 if ( (LA(1)==92) ) {
171                                                                                         class_def();
172                                                                                 }
173                                                                                 else {
174                                                                                         if ( (LA(1)==91) ) {
175                                                                                                 zzmatch(91);
176                                                                                                 
177                                                                                                 if ( class_nest_level==0 )
178                                                                                                 warn("missing class definition for trailing '}'");
179                                                                                                 class_nest_level--;
180  zzCONSUME;
181
182                                                                                         }
183                                                                                 }
184                                                                         }
185                                                                 }
186                                                         }
187                                                 }
188                                         }
189                                 }
190                         }
191                         zzLOOP(zztasp2);
192                 }
193                 zzEXIT(zztasp2);
194                 }
195         }
196         rule();
197         g=zzaArg(zztasp1,3); SynDiag = (Junction *) zzaArg(zztasp1,3 ).left;  
198         {
199                 zzBLOCK(zztasp2);
200                 zzMake0;
201                 {
202                 while ( 1 ) {
203                         if ( !((setwd1[LA(1)]&0x4))) break;
204                         if ( (LA(1)==NonTerminal) ) {
205                                 rule();
206                                 if ( zzaArg(zztasp2,1 ).left!=NULL ) {g.right = NULL; g = Or(g, zzaArg(zztasp2,1));}  
207                         }
208                         else {
209                                 if ( (LA(1)==102) ) {
210                                         aLexclass();
211                                 }
212                                 else {
213                                         if ( (LA(1)==105) ) {
214                                                 token();
215                                         }
216                                         else {
217                                                 if ( (LA(1)==103) ) {
218                                                         error();
219                                                 }
220                                                 else {
221                                                         if ( (LA(1)==104) ) {
222                                                                 tclass();
223                                                         }
224                                                         else {
225                                                                 if ( (LA(1)==92) ) {
226                                                                         class_def();
227                                                                 }
228                                                                 else {
229                                                                         if ( (LA(1)==91) ) {
230                                                                                 zzmatch(91);
231                                                                                 
232                                                                                 if ( class_nest_level==0 )
233                                                                                 warn("missing class definition for trailing '}'");
234                                                                                 class_nest_level--;
235  zzCONSUME;
236
237                                                                         }
238                                                                 }
239                                                         }
240                                                 }
241                                         }
242                                 }
243                         }
244                         zzLOOP(zztasp2);
245                 }
246                 zzEXIT(zztasp2);
247                 }
248         }
249         {
250                 zzBLOCK(zztasp2);
251                 zzMake0;
252                 {
253                 while ( 1 ) {
254                         if ( !((setwd1[LA(1)]&0x8))) break;
255                         if ( (LA(1)==Action) ) {
256                                 zzmatch(Action);
257                                 {
258                                         UserAction *ua = newUserAction(LATEXT(1));
259                                         ua->file = action_file; ua->line = action_line;
260                                         if ( class_nest_level>0 ) list_add(&class_after_actions, ua);
261                                         else list_add(&AfterActions, ua);
262                                 }  
263  zzCONSUME;
264
265                         }
266                         else {
267                                 if ( (LA(1)==101) ) {
268                                         laction();
269                                 }
270                                 else {
271                                         if ( (LA(1)==103) ) {
272                                                 error();
273                                         }
274                                         else {
275                                                 if ( (LA(1)==104) ) {
276                                                         tclass();
277                                                 }
278                                                 else {
279                                                         if ( (LA(1)==92) ) {
280                                                                 class_def();
281                                                         }
282                                                         else {
283                                                                 if ( (LA(1)==91) ) {
284                                                                         zzmatch(91);
285                                                                         
286                                                                         if ( class_nest_level==0 )
287                                                                         warn("missing class definition for trailing '}'");
288                                                                         class_nest_level--;
289  zzCONSUME;
290
291                                                                 }
292                                                         }
293                                                 }
294                                         }
295                                 }
296                         }
297                         zzLOOP(zztasp2);
298                 }
299                 zzEXIT(zztasp2);
300                 }
301         }
302         zzmatch(Eof); zzCONSUME;
303         zzEXIT(zztasp1);
304         return;
305 fail:
306         zzEXIT(zztasp1);
307         CannotContinue=TRUE;  
308         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
309         zzresynch(setwd1, 0x10);
310         }
311 }
312
313 void
314 #ifdef __STDC__
315 class_def(void)
316 #else
317 class_def()
318 #endif
319 {
320         zzRULE;
321         zzBLOCK(zztasp1);
322         zzMake0;
323         {
324         int go=1; char name[MaxRuleName+1];  
325         zzmatch(92); zzCONSUME;
326         {
327                 zzBLOCK(zztasp2);
328                 zzMake0;
329                 {
330                 if ( (LA(1)==NonTerminal) ) {
331                         zzmatch(NonTerminal);
332                         if(go) strncpy(name,LATEXT(1),MaxRuleName);  
333  zzCONSUME;
334
335                 }
336                 else {
337                         if ( (LA(1)==TokenTerm) ) {
338                                 zzmatch(TokenTerm);
339                                 if(go) strncpy(name,LATEXT(1),MaxRuleName);  
340  zzCONSUME;
341
342                         }
343                         else {zzFAIL(1,zzerr1,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
344                 }
345                 zzEXIT(zztasp2);
346                 }
347         }
348         
349         if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0
350         && GenCC ) {
351                 err("only one grammar class allowed in this release");
352                 go = 0;
353         }
354         else strcpy(CurrentClassName, name);
355         if ( !GenCC ) { err("class meta-op used without C++ option"); }  
356         zzmatch(95);
357         
358         no_classes_found = 0;
359         if ( class_nest_level>=1 ) {warn("cannot have nested classes");}
360         else class_nest_level++;
361  zzCONSUME;
362
363         zzEXIT(zztasp1);
364         return;
365 fail:
366         zzEXIT(zztasp1);
367         CannotContinue=TRUE;  
368         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
369         zzresynch(setwd1, 0x20);
370         }
371 }
372
373 void
374 #ifdef __STDC__
375 rule(void)
376 #else
377 rule()
378 #endif
379 {
380         zzRULE;
381         zzBLOCK(zztasp1);
382         zzMake0;
383         {
384         
385         ListNode *ex_groups = NULL;
386         ExceptionGroup *eg;
387         RuleEntry *q; Junction *p; Graph r; int f, l; ECnode *e;
388         set toksrefd, rulesrefd;
389         char *pdecl=NULL, *ret=NULL, *a; CurRetDef = CurParmDef = NULL;
390         CurExGroups = NULL;
391         CurElementLabels = NULL;
392         /* We want a new element label hash table for each rule */
393         if ( Elabel!=NULL ) killHashTable(Elabel);
394         Elabel = newHashTable();
395         attribsRefdFromAction = empty;
396         zzmatch(NonTerminal);
397         q=NULL;
398         if ( hash_get(Rname, LATEXT(1))!=NULL ) {
399                 err(eMsg1("duplicate rule definition: '%s'",LATEXT(1)));
400                 CannotContinue=TRUE;
401         }
402         else
403         {
404                 q = (RuleEntry *)hash_add(Rname,
405                 LATEXT(1),
406                 (Entry *)newRuleEntry(LATEXT(1)));
407                 CurRule = q->str;
408         }
409         CurRuleNode = q;
410         f = CurFile; l = zzline;
411         NumRules++;
412  zzCONSUME;
413
414         {
415                 zzBLOCK(zztasp2);
416                 zzMake0;
417                 {
418                 if ( (LA(1)==96) ) {
419                         zzmatch(96);
420                         if ( q!=NULL ) q->noAST = TRUE;  
421  zzCONSUME;
422
423                 }
424                 zzEXIT(zztasp2);
425                 }
426         }
427         {
428                 zzBLOCK(zztasp2);
429                 zzMake0;
430                 {
431                 ;  
432                 if ( (setwd1[LA(1)]&0x40) ) {
433                         {
434                                 zzBLOCK(zztasp3);
435                                 zzMake0;
436                                 {
437                                 if ( (LA(1)==97) ) {
438                                         zzmatch(97); zzCONSUME;
439                                 }
440                                 zzEXIT(zztasp3);
441                                 }
442                         }
443                         zzmatch(PassAction);
444                         pdecl = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
445                         require(pdecl!=NULL, "rule rule: cannot allocate param decl");
446                         strcpy(pdecl, LATEXT(1));
447                         CurParmDef = pdecl;
448  zzCONSUME;
449
450                 }
451                 zzEXIT(zztasp2);
452                 }
453         }
454         {
455                 zzBLOCK(zztasp2);
456                 zzMake0;
457                 {
458                 if ( (LA(1)==98) ) {
459                         zzmatch(98); zzCONSUME;
460                         zzmatch(PassAction);
461                         ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
462                         require(ret!=NULL, "rule rule: cannot allocate ret type");
463                         strcpy(ret, LATEXT(1));
464                         CurRetDef = ret;
465  zzCONSUME;
466
467                 }
468                 zzEXIT(zztasp2);
469                 }
470         }
471         {
472                 zzBLOCK(zztasp2);
473                 zzMake0;
474                 {
475                 if ( (LA(1)==QuotedTerm) ) {
476                         zzmatch(QuotedTerm);
477                         if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1));  
478  zzCONSUME;
479
480                 }
481                 zzEXIT(zztasp2);
482                 }
483         }
484         
485         if ( GenEClasseForRules && q!=NULL ) {
486                 e = newECnode;
487                 require(e!=NULL, "cannot allocate error class node");
488                 if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);}
489                 else a = q->egroup;
490                 if ( Tnum( a ) == 0 )
491                 {
492                         e->tok = addTname( a );
493                         list_add(&eclasses, (char *)e);
494                         if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
495                         /* refers to itself */
496                         list_add(&(e->elist), mystrdup(q->str));
497                 }
498                 else {
499                         warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a));
500                         if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
501                         free((char *)e);
502                 }
503         }
504         BlkLevel++;  
505         zzmatch(99);
506         inAlt=1;  
507  zzCONSUME;
508
509         block( &toksrefd, &rulesrefd );
510         r = makeBlk(zzaArg(zztasp1,7),0);
511         CurRuleBlk = (Junction *)r.left;
512         CurRuleBlk->blockid = CurBlockID;
513         CurRuleBlk->jtype = RuleBlk;
514         if ( q!=NULL ) CurRuleBlk->rname = q->str;
515         CurRuleBlk->file = f;
516         CurRuleBlk->line = l;
517         CurRuleBlk->pdecl = pdecl;
518         CurRuleBlk->ret = ret;
519         CurRuleBlk->lock = makelocks();
520         CurRuleBlk->pred_lock = makelocks();
521         CurRuleBlk->tokrefs = toksrefd;
522         CurRuleBlk->rulerefs = rulesrefd;
523         p = newJunction();      /* add EndRule Node */
524         ((Junction *)r.right)->p1 = (Node *)p;
525         r.right = (Node *) p;
526         p->jtype = EndRule;
527         p->lock = makelocks();
528         p->pred_lock = makelocks();
529         CurRuleBlk->end = p;
530         if ( q!=NULL ) q->rulenum = NumRules;
531         zzaArg(zztasp1,7) = r;
532         --BlkLevel;  
533         zzmatch(100);
534         inAlt=0;  
535  zzCONSUME;
536
537         {
538                 zzBLOCK(zztasp2);
539                 zzMake0;
540                 {
541                 if ( (LA(1)==Action) ) {
542                         zzmatch(Action);
543                         a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
544                         require(a!=NULL, "rule rule: cannot allocate error action");
545                         strcpy(a, LATEXT(1));
546                         CurRuleBlk->erraction = a;
547  zzCONSUME;
548
549                 }
550                 zzEXIT(zztasp2);
551                 }
552         }
553         {
554                 zzBLOCK(zztasp2);
555                 zzMake0;
556                 {
557                 while ( (LA(1)==122) ) {
558                          eg  = exception_group();
559
560                         if ( eg!=NULL ) {
561                                 list_add(&CurExGroups, (void *)eg);
562                                 if ( eg->label=='\0' ) q->has_rule_exception = 1;
563                         }
564                         zzLOOP(zztasp2);
565                 }
566                 zzEXIT(zztasp2);
567                 }
568         }
569         if ( q==NULL ) zzaArg(zztasp1,0 ).left = NULL; else zzaArg(zztasp1,0) = zzaArg(zztasp1,7);  
570         CurRuleNode = NULL;  
571         CurRuleBlk->exceptions = CurExGroups;  
572         CurRuleBlk->el_labels = CurElementLabels;  
573         zzEXIT(zztasp1);
574         return;
575 fail:
576         zzEXIT(zztasp1);
577         CannotContinue=TRUE;  
578         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
579         zzresynch(setwd1, 0x80);
580         }
581 }
582
583 void
584 #ifdef __STDC__
585 laction(void)
586 #else
587 laction()
588 #endif
589 {
590         zzRULE;
591         zzBLOCK(zztasp1);
592         zzMake0;
593         {
594         char *a;  
595         zzmatch(101); zzCONSUME;
596         zzmatch(Action);
597         
598         a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
599         require(a!=NULL, "rule laction: cannot allocate action");
600         strcpy(a, LATEXT(1));
601         list_add(&LexActions, a);
602  zzCONSUME;
603
604         zzEXIT(zztasp1);
605         return;
606 fail:
607         zzEXIT(zztasp1);
608         CannotContinue=TRUE;  
609         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
610         zzresynch(setwd2, 0x1);
611         }
612 }
613
614 void
615 #ifdef __STDC__
616 aLexclass(void)
617 #else
618 aLexclass()
619 #endif
620 {
621         zzRULE;
622         zzBLOCK(zztasp1);
623         zzMake0;
624         {
625         zzmatch(102); zzCONSUME;
626         zzmatch(TokenTerm);
627         lexclass(mystrdup(LATEXT(1)));  
628  zzCONSUME;
629
630         zzEXIT(zztasp1);
631         return;
632 fail:
633         zzEXIT(zztasp1);
634         CannotContinue=TRUE;  
635         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
636         zzresynch(setwd2, 0x2);
637         }
638 }
639
640 void
641 #ifdef __STDC__
642 error(void)
643 #else
644 error()
645 #endif
646 {
647         zzRULE;
648         zzBLOCK(zztasp1);
649         zzMake0;
650         {
651         char *t=NULL; ECnode *e; int go=1; TermEntry *p;  
652         zzmatch(103); zzCONSUME;
653         {
654                 zzBLOCK(zztasp2);
655                 zzMake0;
656                 {
657                 ;  
658                 if ( (LA(1)==TokenTerm) ) {
659                         zzmatch(TokenTerm);
660                         t=mystrdup(LATEXT(1));  
661  zzCONSUME;
662
663                 }
664                 else {
665                         if ( (LA(1)==QuotedTerm) ) {
666                                 zzmatch(QuotedTerm);
667                                 t=mystrdup(LATEXT(1));  
668  zzCONSUME;
669
670                         }
671                         else {zzFAIL(1,zzerr2,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
672                 }
673                 zzEXIT(zztasp2);
674                 }
675         }
676         e = newECnode;
677         require(e!=NULL, "cannot allocate error class node");
678         e->lexclass = CurrentLexClass;
679         if ( Tnum( (t=StripQuotes(t)) ) == 0 )
680         {
681                 if ( hash_get(Texpr, t) != NULL )
682                 warn(eMsg1("errclass name conflicts with regular expression  '%s'",t));
683                 e->tok = addTname( t );
684                 set_orel(e->tok, &imag_tokens);
685                 require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
686                 "hash table mechanism is broken");
687                 p->classname = 1;       /* entry is errclass name, not token */
688                 list_add(&eclasses, (char *)e);
689         }
690         else
691         {
692         warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t));
693         free( (char *)e );
694         go=0;
695 }
696         zzmatch(95); zzCONSUME;
697         {
698                 zzBLOCK(zztasp2);
699                 zzMake0;
700                 {
701                 if ( (LA(1)==NonTerminal) ) {
702                         zzmatch(NonTerminal);
703                         if ( go ) t=mystrdup(LATEXT(1));  
704  zzCONSUME;
705
706                 }
707                 else {
708                         if ( (LA(1)==TokenTerm) ) {
709                                 zzmatch(TokenTerm);
710                                 if ( go ) t=mystrdup(LATEXT(1));  
711  zzCONSUME;
712
713                         }
714                         else {
715                                 if ( (LA(1)==QuotedTerm) ) {
716                                         zzmatch(QuotedTerm);
717                                         if ( go ) t=mystrdup(LATEXT(1));  
718  zzCONSUME;
719
720                                 }
721                                 else {zzFAIL(1,zzerr3,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
722                         }
723                 }
724                 zzEXIT(zztasp2);
725                 }
726         }
727         if ( go ) list_add(&(e->elist), t);  
728         {
729                 zzBLOCK(zztasp2);
730                 zzMake0;
731                 {
732                 while ( (setwd2[LA(1)]&0x4) ) {
733                         {
734                                 zzBLOCK(zztasp3);
735                                 zzMake0;
736                                 {
737                                 if ( (LA(1)==NonTerminal) ) {
738                                         zzmatch(NonTerminal);
739                                         if ( go ) t=mystrdup(LATEXT(1));  
740  zzCONSUME;
741
742                                 }
743                                 else {
744                                         if ( (LA(1)==TokenTerm) ) {
745                                                 zzmatch(TokenTerm);
746                                                 if ( go ) t=mystrdup(LATEXT(1));  
747  zzCONSUME;
748
749                                         }
750                                         else {
751                                                 if ( (LA(1)==QuotedTerm) ) {
752                                                         zzmatch(QuotedTerm);
753                                                         if ( go ) t=mystrdup(LATEXT(1));  
754  zzCONSUME;
755
756                                                 }
757                                                 else {zzFAIL(1,zzerr4,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
758                                         }
759                                 }
760                                 zzEXIT(zztasp3);
761                                 }
762                         }
763                         if ( go ) list_add(&(e->elist), t);  
764                         zzLOOP(zztasp2);
765                 }
766                 zzEXIT(zztasp2);
767                 }
768         }
769         zzmatch(91); zzCONSUME;
770         zzEXIT(zztasp1);
771         return;
772 fail:
773         zzEXIT(zztasp1);
774         CannotContinue=TRUE;  
775         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
776         zzresynch(setwd2, 0x8);
777         }
778 }
779
780 void
781 #ifdef __STDC__
782 tclass(void)
783 #else
784 tclass()
785 #endif
786 {
787         zzRULE;
788         zzBLOCK(zztasp1);
789         zzMake0;
790         {
791         char *t=NULL; TCnode *e; int go=1,tok; TermEntry *p, *term;  
792         zzmatch(104); zzCONSUME;
793         zzmatch(TokenTerm);
794         t=mystrdup(LATEXT(1));  
795  zzCONSUME;
796
797         e = newTCnode;
798         require(e!=NULL, "cannot allocate token class node");
799         e->lexclass = CurrentLexClass;
800         if ( Tnum( t ) == 0 )
801         {
802                 e->tok = addTname( t );
803                 set_orel(e->tok, &imag_tokens);
804                 set_orel(e->tok, &tokclasses);
805                 require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
806                 "hash table mechanism is broken");
807                 p->classname = 1;       /* entry is class name, not token */
808                 p->tclass = e;          /* save ptr to this tclass def */
809                 list_add(&tclasses, (char *)e);
810         }
811         else
812         {
813         warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t));
814         free( (char *)e );
815         go=0;
816 }
817         zzmatch(95); zzCONSUME;
818         {
819                 zzBLOCK(zztasp2);
820                 zzMake0;
821                 {
822                 while ( (setwd2[LA(1)]&0x10) ) {
823                         {
824                                 zzBLOCK(zztasp3);
825                                 zzMake0;
826                                 {
827                                 if ( (LA(1)==TokenTerm) ) {
828                                         zzmatch(TokenTerm);
829                                         if ( go ) {
830                                                 term = (TermEntry *) hash_get(Tname, LATEXT(1));
831                                                 if ( term==NULL && UserDefdTokens ) {
832                                                         err("implicit token definition not allowed with #tokdefs");
833                                                         go = 0;
834                                                 }
835                                                 else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));}
836                                         }  
837  zzCONSUME;
838
839                                 }
840                                 else {
841                                         if ( (LA(1)==QuotedTerm) ) {
842                                                 zzmatch(QuotedTerm);
843                                                 if ( go ) {
844                                                         term = (TermEntry *) hash_get(Texpr, LATEXT(1));
845                                                         if ( term==NULL && UserDefdTokens ) {
846                                                                 err("implicit token definition not allowed with #tokdefs");
847                                                                 go = 0;
848                                                         }
849                                                         else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));}
850                                                 }  
851  zzCONSUME;
852
853                                         }
854                                         else {zzFAIL(1,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
855                                 }
856                                 zzEXIT(zztasp3);
857                                 }
858                         }
859                         if ( go ) list_add(&(e->tlist), t);  
860                         zzLOOP(zztasp2);
861                 }
862                 zzEXIT(zztasp2);
863                 }
864         }
865         zzmatch(91); zzCONSUME;
866         zzEXIT(zztasp1);
867         return;
868 fail:
869         zzEXIT(zztasp1);
870         CannotContinue=TRUE;  
871         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
872         zzresynch(setwd2, 0x20);
873         }
874 }
875
876 void
877 #ifdef __STDC__
878 token(void)
879 #else
880 token()
881 #endif
882 {
883         zzRULE;
884         zzBLOCK(zztasp1);
885         zzMake0;
886         {
887         char *t=NULL, *e=NULL, *a=NULL; int tnum=0;  
888         zzmatch(105); zzCONSUME;
889         {
890                 zzBLOCK(zztasp2);
891                 zzMake0;
892                 {
893                 if ( (LA(1)==TokenTerm) ) {
894                         zzmatch(TokenTerm);
895                         t=mystrdup(LATEXT(1));  
896  zzCONSUME;
897
898                         {
899                                 zzBLOCK(zztasp3);
900                                 zzMake0;
901                                 {
902                                 if ( (LA(1)==106) ) {
903                                         zzmatch(106); zzCONSUME;
904                                         zzmatch(107);
905                                         tnum = atoi(LATEXT(1));  
906  zzCONSUME;
907
908                                 }
909                                 zzEXIT(zztasp3);
910                                 }
911                         }
912                 }
913                 zzEXIT(zztasp2);
914                 }
915         }
916         {
917                 zzBLOCK(zztasp2);
918                 zzMake0;
919                 {
920                 if ( (LA(1)==QuotedTerm) ) {
921                         zzmatch(QuotedTerm);
922                         e=mystrdup(LATEXT(1));  
923  zzCONSUME;
924
925                 }
926                 zzEXIT(zztasp2);
927                 }
928         }
929         {
930                 zzBLOCK(zztasp2);
931                 zzMake0;
932                 {
933                 if ( (LA(1)==Action) ) {
934                         zzmatch(Action);
935                         
936                         a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
937                         require(a!=NULL, "rule token: cannot allocate action");
938                         strcpy(a, LATEXT(1));
939  zzCONSUME;
940
941                 }
942                 zzEXIT(zztasp2);
943                 }
944         }
945         chkToken(t, e, a, tnum);  
946         zzEXIT(zztasp1);
947         return;
948 fail:
949         zzEXIT(zztasp1);
950         CannotContinue=TRUE;  
951         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
952         zzresynch(setwd2, 0x40);
953         }
954 }
955
956 void
957 #ifdef __STDC__
958 block( set *toksrefd, set *rulesrefd )
959 #else
960 block(toksrefd,rulesrefd)
961  set *toksrefd;
962 set *rulesrefd ;
963 #endif
964 {
965         zzRULE;
966         zzBLOCK(zztasp1);
967         zzMake0;
968         {
969         
970         Graph g, b;
971         set saveblah;
972         int saveinalt = inAlt;
973         ExceptionGroup *eg;
974         * toksrefd = empty;
975         * rulesrefd = empty;
976         set_clr(AST_nodes_refd_in_actions);
977         CurBlockID++;
978         CurAltNum = 1;
979         saveblah = attribsRefdFromAction;
980         attribsRefdFromAction = empty;
981         alt( toksrefd,rulesrefd );
982         b = g = zzaArg(zztasp1,1);  
983         
984         if ( ((Junction *)g.left)->p1->ntype == nAction )
985         {
986                 if ( !((ActionNode *)(((Junction *)g.left)->p1))->is_predicate )
987                 {
988                         ((ActionNode *)(((Junction *)g.left)->p1))->init_action = TRUE;
989                 }
990         }
991         ((Junction *)g.left)->blockid = CurBlockID;
992         {
993                 zzBLOCK(zztasp2);
994                 zzMake0;
995                 {
996                 while ( (LA(1)==122) ) {
997                          eg  = exception_group();
998
999                         
1000                         if ( eg!=NULL ) {
1001                                 eg->altID = makeAltID(CurBlockID,CurAltNum);
1002                                 CurAltStart->exception_label = eg->altID;
1003                                 list_add(&CurExGroups, (void *)eg);
1004                         }
1005                         zzLOOP(zztasp2);
1006                 }
1007                 zzEXIT(zztasp2);
1008                 }
1009         }
1010         CurAltNum++;  
1011         {
1012                 zzBLOCK(zztasp2);
1013                 zzMake0;
1014                 {
1015                 while ( (LA(1)==108) ) {
1016                         zzmatch(108);
1017                         inAlt=1;  
1018  zzCONSUME;
1019
1020                         alt( toksrefd,rulesrefd );
1021                         g = Or(g, zzaArg(zztasp2,2));  
1022                         
1023                         ((Junction *)g.left)->blockid = CurBlockID;
1024                         {
1025                                 zzBLOCK(zztasp3);
1026                                 zzMake0;
1027                                 {
1028                                 while ( (LA(1)==122) ) {
1029                                          eg  = exception_group();
1030
1031                                         
1032                                         if ( eg!=NULL ) {
1033                                                 eg->altID = makeAltID(CurBlockID,CurAltNum);
1034                                                 CurAltStart->exception_label = eg->altID;
1035                                                 list_add(&CurExGroups, (void *)eg);
1036                                         }
1037                                         zzLOOP(zztasp3);
1038                                 }
1039                                 zzEXIT(zztasp3);
1040                                 }
1041                         }
1042                         CurAltNum++;  
1043                         zzLOOP(zztasp2);
1044                 }
1045                 zzEXIT(zztasp2);
1046                 }
1047         }
1048         zzaArg(zztasp1,0) = b;  
1049         attribsRefdFromAction = saveblah; inAlt = saveinalt;  
1050         zzEXIT(zztasp1);
1051         return;
1052 fail:
1053         zzEXIT(zztasp1);
1054         CannotContinue=TRUE;  
1055         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
1056         zzresynch(setwd2, 0x80);
1057         }
1058 }
1059
1060 void
1061 #ifdef __STDC__
1062 alt( set *toksrefd, set *rulesrefd )
1063 #else
1064 alt(toksrefd,rulesrefd)
1065  set *toksrefd;
1066 set *rulesrefd ;
1067 #endif
1068 {
1069         zzRULE;
1070         zzBLOCK(zztasp1);
1071         zzMake0;
1072         {
1073         int n=0,ne=0; Graph g; int e_num=0, not=0; Node *node; set elems, dif;
1074         int first_on_line = 1, use_def_MT_handler = 0;
1075         g.left=NULL; g.right=NULL;
1076         CurAltStart = NULL;
1077         elems = empty;
1078         inAlt = 1;
1079         {
1080                 zzBLOCK(zztasp2);
1081                 zzMake0;
1082                 {
1083                 if ( (LA(1)==84) ) {
1084                         zzmatch(84);
1085                         use_def_MT_handler = 1;  
1086  zzCONSUME;
1087
1088                 }
1089                 zzEXIT(zztasp2);
1090                 }
1091         }
1092         {
1093                 zzBLOCK(zztasp2);
1094                 zzMake0;
1095                 {
1096                 int tok;  
1097                 while ( (setwd3[LA(1)]&0x1) ) {
1098                         {
1099                                 zzBLOCK(zztasp3);
1100                                 zzMake0;
1101                                 {
1102                                 not=0;  
1103                                 if ( (LA(1)==109) ) {
1104                                         zzmatch(109);
1105                                         not=1;  
1106  zzCONSUME;
1107
1108                                 }
1109                                 zzEXIT(zztasp3);
1110                                 }
1111                         }
1112                          node  = element( not, first_on_line, use_def_MT_handler );
1113
1114                         if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0;  
1115                         
1116                         if ( zzaArg(zztasp2,2 ).left!=NULL ) {
1117                                 g = Cat(g, zzaArg(zztasp2,2));
1118                                 n++;
1119                                 if ( node!=NULL ) {
1120                                         if ( node->ntype!=nAction ) e_num++;
1121                                         /* record record number of all rule and token refs */
1122                                         if ( node->ntype==nToken ) {
1123                                                 TokNode *tk = (TokNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1;
1124                                                 tk->elnum = e_num;
1125                                                 set_orel(e_num, &elems);
1126                                         }
1127                                         else if ( node->ntype==nRuleRef ) {
1128                                                 RuleRefNode *rn = (RuleRefNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1;
1129                                                 rn->elnum = e_num;
1130                                                 set_orel(e_num,  rulesrefd);
1131                                         }
1132                                 }
1133                         }
1134                         zzLOOP(zztasp2);
1135                 }
1136                 zzEXIT(zztasp2);
1137                 }
1138         }
1139         if ( n == 0 ) g = emptyAlt();
1140         zzaArg(zztasp1,0) = g;
1141         /* We want to reduce number of LT(i) calls and the number of
1142         * local attribute variables in C++ mode (for moment, later we'll
1143         * do for C also).  However, if trees are being built, they
1144         * require most of the attrib variables to create the tree nodes
1145         * with; therefore, we gen a token ptr for each token ref in C++
1146         */
1147         if ( GenCC && !GenAST )
1148         {
1149         /* This now free's the temp set -ATG 5/6/95 */
1150         set temp;
1151         temp = set_and(elems, attribsRefdFromAction);
1152         set_orin( toksrefd, temp);
1153         set_free(temp);
1154 }
1155 else set_orin( toksrefd, elems);
1156 if ( GenCC ) {
1157         dif = set_dif(attribsRefdFromAction, elems);
1158         if ( set_deg(dif)>0 )
1159         err("one or more $i in action(s) refer to non-token elements");
1160         set_free(dif);
1161 }
1162 set_free(elems);
1163 set_free(attribsRefdFromAction);
1164 inAlt = 0;
1165         zzEXIT(zztasp1);
1166         return;
1167 fail:
1168         zzEXIT(zztasp1);
1169         CannotContinue=TRUE;  
1170         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
1171         zzresynch(setwd3, 0x2);
1172         }
1173 }
1174
1175  LabelEntry * 
1176 #ifdef __STDC__
1177 element_label(void)
1178 #else
1179 element_label()
1180 #endif
1181 {
1182          LabelEntry *    _retv;
1183         PURIFY(_retv,sizeof( LabelEntry *       ))
1184         zzRULE;
1185         zzBLOCK(zztasp1);
1186         zzMake0;
1187         {
1188         TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;  
1189         zzmatch(LABEL);
1190         lab = mystrdup(LATEXT(1));  
1191  zzCONSUME;
1192
1193         
1194         UsedNewStyleLabel = 1;
1195         if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i");
1196         t = (TermEntry *) hash_get(Tname, lab);
1197         if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab);
1198         if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab);
1199         if ( t!=NULL ) {
1200                 err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab));
1201                 _retv = NULL;
1202         }
1203         else if ( r!=NULL ) {
1204                 err(eMsg1("label definition clashes with rule definition: '%s'", lab));
1205                 _retv = NULL;
1206         }
1207         else {
1208                 /* we don't clash with anybody else */
1209                 l = (LabelEntry *) hash_get(Elabel, lab);
1210                 if ( l==NULL ) {        /* ok to add new element label */
1211                 l = (LabelEntry *)hash_add(Elabel,
1212                 lab,
1213                 (Entry *)newLabelEntry(lab));
1214                 /* add to list of element labels for this rule */
1215                 list_add(&CurElementLabels, (void *)lab);
1216                 _retv = l;
1217         }
1218         else {
1219         err(eMsg1("label definitions must be unique per rule: '%s'", lab));
1220         _retv = NULL;
1221 }
1222 }
1223         zzmatch(99); zzCONSUME;
1224         zzEXIT(zztasp1);
1225         return _retv;
1226 fail:
1227         zzEXIT(zztasp1);
1228         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
1229         zzresynch(setwd3, 0x4);
1230         return _retv;
1231         }
1232 }
1233
1234  Node * 
1235 #ifdef __STDC__
1236 element( int not, int first_on_line, int use_def_MT_handler )
1237 #else
1238 element(not,first_on_line,use_def_MT_handler)
1239  int not;
1240 int first_on_line;
1241 int use_def_MT_handler ;
1242 #endif
1243 {
1244          Node *          _retv;
1245         PURIFY(_retv,sizeof( Node *     ))
1246         zzRULE;
1247         zzBLOCK(zztasp1);
1248         zzMake0;
1249         {
1250         
1251         Attrib blk;
1252         Predicate *pred = NULL;
1253         int local_use_def_MT_handler=0;
1254         ActionNode *act;
1255         RuleRefNode *rr;
1256         set toksrefd, rulesrefd;
1257         TermEntry *term;
1258         TokNode *p=NULL; RuleRefNode *q; int approx=0;
1259         LabelEntry *label=NULL;
1260         _retv = NULL;
1261         if ( (setwd3[LA(1)]&0x8) ) {
1262                 {
1263                         zzBLOCK(zztasp2);
1264                         zzMake0;
1265                         {
1266                         if ( (LA(1)==LABEL) ) {
1267                                  label  = element_label();
1268
1269                         }
1270                         zzEXIT(zztasp2);
1271                         }
1272                 }
1273                 {
1274                         zzBLOCK(zztasp2);
1275                         zzMake0;
1276                         {
1277                         if ( (LA(1)==TokenTerm) ) {
1278                                 zzmatch(TokenTerm);
1279                                 
1280                                 term = (TermEntry *) hash_get(Tname, LATEXT(1));
1281                                 if ( term==NULL && UserDefdTokens ) {
1282                                         err("implicit token definition not allowed with #tokdefs");
1283                                         zzaRet.left = zzaRet.right = NULL;
1284                                 }
1285                                 else {
1286                                         zzaRet = buildToken(LATEXT(1));
1287                                         p=((TokNode *)((Junction *)zzaRet.left)->p1);
1288                                         term = (TermEntry *) hash_get(Tname, LATEXT(1));
1289                                         require( term!= NULL, "hash table mechanism is broken");
1290                                         p->tclass = term->tclass;
1291                                         p->complement =  not;
1292                                         if ( label!=NULL ) {
1293                                                 p->el_label = label->str;
1294                                                 label->elem = (Node *)p;
1295                                         }
1296                                 }
1297  zzCONSUME;
1298
1299                                 {
1300                                         zzBLOCK(zztasp3);
1301                                         zzMake0;
1302                                         {
1303                                         if ( (LA(1)==110) ) {
1304                                                 zzmatch(110); zzCONSUME;
1305                                                 {
1306                                                         zzBLOCK(zztasp4);
1307                                                         zzMake0;
1308                                                         {
1309                                                         if ( (LA(1)==QuotedTerm) ) {
1310                                                                 zzmatch(QuotedTerm);
1311                                                                 if ( p!=NULL ) setUpperRange(p, LATEXT(1));  
1312  zzCONSUME;
1313
1314                                                         }
1315                                                         else {
1316                                                                 if ( (LA(1)==TokenTerm) ) {
1317                                                                         zzmatch(TokenTerm);
1318                                                                         if ( p!=NULL ) setUpperRange(p, LATEXT(1));  
1319  zzCONSUME;
1320
1321                                                                 }
1322                                                                 else {zzFAIL(1,zzerr6,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1323                                                         }
1324                                                         zzEXIT(zztasp4);
1325                                                         }
1326                                                 }
1327                                         }
1328                                         zzEXIT(zztasp3);
1329                                         }
1330                                 }
1331                                 
1332                                 if ( p!=NULL && (p->upper_range!=0 || p->tclass ||  not) )
1333                                 list_add(&MetaTokenNodes, (void *)p);
1334                                 {
1335                                         zzBLOCK(zztasp3);
1336                                         zzMake0;
1337                                         {
1338                                         if ( (LA(1)==111) ) {
1339                                                 zzmatch(111);
1340                                                 if ( p!=NULL ) p->astnode=ASTroot;  
1341  zzCONSUME;
1342
1343                                         }
1344                                         else {
1345                                                 if ( (setwd3[LA(1)]&0x10) ) {
1346                                                         if ( p!=NULL ) p->astnode=ASTchild;  
1347                                                 }
1348                                                 else {
1349                                                         if ( (LA(1)==96) ) {
1350                                                                 zzmatch(96);
1351                                                                 if ( p!=NULL ) p->astnode=ASTexclude;  
1352  zzCONSUME;
1353
1354                                                         }
1355                                                         else {zzFAIL(1,zzerr7,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1356                                                 }
1357                                         }
1358                                         zzEXIT(zztasp3);
1359                                         }
1360                                 }
1361                                 {
1362                                         zzBLOCK(zztasp3);
1363                                         zzMake0;
1364                                         {
1365                                         if ( (LA(1)==84) ) {
1366                                                 zzmatch(84);
1367                                                 local_use_def_MT_handler = 1;  
1368  zzCONSUME;
1369
1370                                         }
1371                                         zzEXIT(zztasp3);
1372                                         }
1373                                 }
1374                                 
1375                                 if ( p!=NULL &&  first_on_line ) {
1376                                         CurAltStart = (Junction *)zzaRet.left;
1377                                         p->altstart = CurAltStart;
1378                                 }
1379                                 if ( p!=NULL )
1380                                 p->use_def_MT_handler =  use_def_MT_handler || local_use_def_MT_handler;
1381                                 _retv = (Node *)p;
1382                         }
1383                         else {
1384                                 if ( (LA(1)==QuotedTerm) ) {
1385                                         zzmatch(QuotedTerm);
1386                                         
1387                                         term = (TermEntry *) hash_get(Texpr, LATEXT(1));
1388                                         if ( term==NULL && UserDefdTokens ) {
1389                                                 err("implicit token definition not allowed with #tokdefs");
1390                                                 zzaRet.left = zzaRet.right = NULL;
1391                                         }
1392                                         else {
1393                                                 zzaRet = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1);
1394                                                 p->complement =  not;
1395                                                 if ( label!=NULL ) {
1396                                                         p->el_label = label->str;
1397                                                         label->elem = (Node *)p;
1398                                                 }
1399                                         }
1400  zzCONSUME;
1401
1402                                         {
1403                                                 zzBLOCK(zztasp3);
1404                                                 zzMake0;
1405                                                 {
1406                                                 if ( (LA(1)==110) ) {
1407                                                         zzmatch(110); zzCONSUME;
1408                                                         {
1409                                                                 zzBLOCK(zztasp4);
1410                                                                 zzMake0;
1411                                                                 {
1412                                                                 if ( (LA(1)==QuotedTerm) ) {
1413                                                                         zzmatch(QuotedTerm);
1414                                                                         if ( p!=NULL ) setUpperRange(p, LATEXT(1));  
1415  zzCONSUME;
1416
1417                                                                 }
1418                                                                 else {
1419                                                                         if ( (LA(1)==TokenTerm) ) {
1420                                                                                 zzmatch(TokenTerm);
1421                                                                                 if ( p!=NULL ) setUpperRange(p, LATEXT(1));  
1422  zzCONSUME;
1423
1424                                                                         }
1425                                                                         else {zzFAIL(1,zzerr8,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1426                                                                 }
1427                                                                 zzEXIT(zztasp4);
1428                                                                 }
1429                                                         }
1430                                                 }
1431                                                 zzEXIT(zztasp3);
1432                                                 }
1433                                         }
1434                                         {
1435                                                 zzBLOCK(zztasp3);
1436                                                 zzMake0;
1437                                                 {
1438                                                 if ( (LA(1)==111) ) {
1439                                                         zzmatch(111);
1440                                                         if ( p!=NULL ) p->astnode=ASTroot;  
1441  zzCONSUME;
1442
1443                                                 }
1444                                                 else {
1445                                                         if ( (setwd3[LA(1)]&0x20) ) {
1446                                                                 if ( p!=NULL ) p->astnode=ASTchild;  
1447                                                         }
1448                                                         else {
1449                                                                 if ( (LA(1)==96) ) {
1450                                                                         zzmatch(96);
1451                                                                         if ( p!=NULL ) p->astnode=ASTexclude;  
1452  zzCONSUME;
1453
1454                                                                 }
1455                                                                 else {zzFAIL(1,zzerr9,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1456                                                         }
1457                                                 }
1458                                                 zzEXIT(zztasp3);
1459                                                 }
1460                                         }
1461                                         {
1462                                                 zzBLOCK(zztasp3);
1463                                                 zzMake0;
1464                                                 {
1465                                                 if ( (LA(1)==84) ) {
1466                                                         zzmatch(84);
1467                                                         local_use_def_MT_handler = 1;  
1468  zzCONSUME;
1469
1470                                                 }
1471                                                 zzEXIT(zztasp3);
1472                                                 }
1473                                         }
1474                                         
1475                                         if ( p!=NULL && (p->upper_range!=0 || p->tclass ||  not) )
1476                                         list_add(&MetaTokenNodes, (void *)p);
1477                                         
1478                                         if (  first_on_line ) {
1479                                                 CurAltStart = (Junction *)zzaRet.left;
1480                                                 p->altstart = CurAltStart;
1481                                         }
1482                                         if ( p!=NULL )
1483                                         p->use_def_MT_handler =  use_def_MT_handler || local_use_def_MT_handler;
1484                                         _retv = (Node *)p;
1485                                 }
1486                                 else {
1487                                         if ( (LA(1)==WildCard) ) {
1488                                                 if (  not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')");  
1489                                                 zzmatch(WildCard);
1490                                                 zzaRet = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1);  
1491  zzCONSUME;
1492
1493                                                 {
1494                                                         zzBLOCK(zztasp3);
1495                                                         zzMake0;
1496                                                         {
1497                                                         if ( (LA(1)==111) ) {
1498                                                                 zzmatch(111);
1499                                                                 p->astnode=ASTroot;  
1500  zzCONSUME;
1501
1502                                                         }
1503                                                         else {
1504                                                                 if ( (setwd3[LA(1)]&0x40) ) {
1505                                                                         p->astnode=ASTchild;  
1506                                                                 }
1507                                                                 else {
1508                                                                         if ( (LA(1)==96) ) {
1509                                                                                 zzmatch(96);
1510                                                                                 p->astnode=ASTexclude;  
1511  zzCONSUME;
1512
1513                                                                         }
1514                                                                         else {zzFAIL(1,zzerr10,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1515                                                                 }
1516                                                         }
1517                                                         zzEXIT(zztasp3);
1518                                                         }
1519                                                 }
1520                                                 list_add(&MetaTokenNodes, (void *)p);  
1521                                                 
1522                                                 if (  first_on_line ) {
1523                                                         CurAltStart = (Junction *)zzaRet.left;
1524                                                         p->altstart = CurAltStart;
1525                                                         if ( label!=NULL ) {
1526                                                                 p->el_label = label->str;
1527                                                                 label->elem = (Node *)p;
1528                                                         }
1529                                                 }
1530                                                 _retv = (Node *)p;
1531                                         }
1532                                         else {
1533                                                 if ( (LA(1)==NonTerminal) ) {
1534                                                         if (  not ) warn("~ NONTERMINAL is an undefined operation");  
1535                                                         zzmatch(NonTerminal);
1536                                                         zzaRet = buildRuleRef(LATEXT(1));  
1537  zzCONSUME;
1538
1539                                                         {
1540                                                                 zzBLOCK(zztasp3);
1541                                                                 zzMake0;
1542                                                                 {
1543                                                                 if ( (LA(1)==96) ) {
1544                                                                         zzmatch(96);
1545                                                                         q = (RuleRefNode *) ((Junction *)zzaRet.left)->p1;
1546                                                                         q->astnode=ASTexclude;  
1547  zzCONSUME;
1548
1549                                                                 }
1550                                                                 zzEXIT(zztasp3);
1551                                                                 }
1552                                                         }
1553                                                         {
1554                                                                 zzBLOCK(zztasp3);
1555                                                                 zzMake0;
1556                                                                 {
1557                                                                 if ( (setwd3[LA(1)]&0x80) ) {
1558                                                                         {
1559                                                                                 zzBLOCK(zztasp4);
1560                                                                                 zzMake0;
1561                                                                                 {
1562                                                                                 if ( (LA(1)==97) ) {
1563                                                                                         zzmatch(97); zzCONSUME;
1564                                                                                 }
1565                                                                                 zzEXIT(zztasp4);
1566                                                                                 }
1567                                                                         }
1568                                                                         zzmatch(PassAction);
1569                                                                         addParm(((Junction *)zzaRet.left)->p1, LATEXT(1));  
1570  zzCONSUME;
1571
1572                                                                 }
1573                                                                 zzEXIT(zztasp3);
1574                                                                 }
1575                                                         }
1576                                                         rr=(RuleRefNode *) ((Junction *)zzaRet.left)->p1;  
1577                                                         {
1578                                                                 zzBLOCK(zztasp3);
1579                                                                 zzMake0;
1580                                                                 {
1581                                                                 char *a;  
1582                                                                 if ( (LA(1)==98) ) {
1583                                                                         zzmatch(98); zzCONSUME;
1584                                                                         zzmatch(PassAction);
1585                                                                         
1586                                                                         a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1587                                                                         require(a!=NULL, "rule element: cannot allocate assignment");
1588                                                                         strcpy(a, LATEXT(1));
1589                                                                         rr->assign = a;
1590  zzCONSUME;
1591
1592                                                                 }
1593                                                                 zzEXIT(zztasp3);
1594                                                                 }
1595                                                         }
1596                                                         
1597                                                         if ( label!=NULL ) {
1598                                                                 rr->el_label = label->str;
1599                                                                 label->elem = (Node *)rr;
1600                                                         }
1601                                                         if (  first_on_line ) {
1602                                                                 CurAltStart = (Junction *)zzaRet.left;
1603                                                                 ((RuleRefNode *)((Junction *)zzaRet.left)->p1)->altstart = CurAltStart;
1604                                                         }
1605                                                         _retv = (Node *)rr;
1606                                                 }
1607                                                 else {zzFAIL(1,zzerr11,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1608                                         }
1609                                 }
1610                         }
1611                         zzEXIT(zztasp2);
1612                         }
1613                 }
1614         }
1615         else {
1616                 if ( (LA(1)==Action) ) {
1617                         if (  not )     warn("~ ACTION is an undefined operation");  
1618                         zzmatch(Action);
1619                         zzaArg(zztasp1,0) = buildAction(LATEXT(1),action_file,action_line, 0);  
1620  zzCONSUME;
1621
1622                         if (  first_on_line ) CurAltStart = (Junction *)zzaArg(zztasp1,0 ).left;  
1623                         _retv = (Node *) ((Junction *)zzaArg(zztasp1,0 ).left)->p1;  
1624                 }
1625                 else {
1626                         if ( (LA(1)==Pred) ) {
1627                                 if (  not )     warn("~ SEMANTIC-PREDICATE is an undefined operation");  
1628                                 zzmatch(Pred);
1629                                 zzaArg(zztasp1,0) = buildAction(LATEXT(1),action_file,action_line, 1);  
1630  zzCONSUME;
1631
1632                                 act = (ActionNode *) ((Junction *)zzaArg(zztasp1,0 ).left)->p1;  
1633                                 {
1634                                         zzBLOCK(zztasp2);
1635                                         zzMake0;
1636                                         {
1637                                         char *a;  
1638                                         if ( (LA(1)==PassAction) ) {
1639                                                 zzmatch(PassAction);
1640                                                 
1641                                                 a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1642                                                 require(a!=NULL, "rule element: cannot allocate predicate fail action");
1643                                                 strcpy(a, LATEXT(1));
1644                                                 act->pred_fail = a;
1645  zzCONSUME;
1646
1647                                         }
1648                                         zzEXIT(zztasp2);
1649                                         }
1650                                 }
1651                                 if (  first_on_line ) CurAltStart = (Junction *)zzaArg(zztasp1,0 ).left;  
1652                                 _retv = (Node *)act;  
1653                         }
1654                         else {
1655                                 if ( (setwd4[LA(1)]&0x1) ) {
1656                                         if (  not )     warn("~ BLOCK is an undefined operation");  
1657                                         BlkLevel++;  
1658                                         {
1659                                                 zzBLOCK(zztasp2);
1660                                                 zzMake0;
1661                                                 {
1662                                                 if ( (LA(1)==112) ) {
1663                                                         zzmatch(112); zzCONSUME;
1664                                                         {
1665                                                                 zzBLOCK(zztasp3);
1666                                                                 zzMake0;
1667                                                                 {
1668                                                                 if ( (LA(1)==113) ) {
1669                                                                         zzmatch(113);
1670                                                                         approx=LL_k;  
1671  zzCONSUME;
1672
1673                                                                 }
1674                                                                 else {
1675                                                                         if ( (LA(1)==114) ) {
1676                                                                                 zzmatch(114);
1677                                                                                 approx = 1;  
1678  zzCONSUME;
1679
1680                                                                         }
1681                                                                         else {
1682                                                                                 if ( (LA(1)==115) ) {
1683                                                                                         zzmatch(115);
1684                                                                                         approx = 2;  
1685  zzCONSUME;
1686
1687                                                                                 }
1688                                                                                 else {zzFAIL(1,zzerr12,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1689                                                                         }
1690                                                                 }
1691                                                                 zzEXIT(zztasp3);
1692                                                                 }
1693                                                         }
1694                                                 }
1695                                                 zzEXIT(zztasp2);
1696                                                 }
1697                                         }
1698                                         {
1699                                                 zzBLOCK(zztasp2);
1700                                                 zzMake0;
1701                                                 {
1702                                                 if ( (LA(1)==116) ) {
1703                                                         zzmatch(116); zzCONSUME;
1704                                                         block( &toksrefd,&rulesrefd );
1705                                                         zzmatch(117);
1706                                                         blk = zzaRet = zzaArg(zztasp2,2); --BlkLevel;  
1707  zzCONSUME;
1708
1709                                                         {
1710                                                                 zzBLOCK(zztasp3);
1711                                                                 zzMake0;
1712                                                                 {
1713                                                                 if ( (LA(1)==118) ) {
1714                                                                         zzmatch(118);
1715                                                                         zzaRet = makeLoop(zzaRet,approx);  
1716  zzCONSUME;
1717
1718                                                                 }
1719                                                                 else {
1720                                                                         if ( (LA(1)==119) ) {
1721                                                                                 zzmatch(119);
1722                                                                                 zzaRet = makePlus(zzaRet,approx);  
1723  zzCONSUME;
1724
1725                                                                         }
1726                                                                         else {
1727                                                                                 if ( (LA(1)==120) ) {
1728                                                                                         zzmatch(120); zzCONSUME;
1729                                                                                         {
1730                                                                                                 zzBLOCK(zztasp4);
1731                                                                                                 zzMake0;
1732                                                                                                 {
1733                                                                                                 if ( (LA(1)==121) ) {
1734                                                                                                         zzmatch(121); zzCONSUME;
1735                                                                                                         zzmatch(Pred);
1736                                                                                                         zzaRet = buildAction(LATEXT(1),action_file,action_line,1);  
1737  zzCONSUME;
1738
1739                                                                                                         act = (ActionNode *) ((Junction *)zzaRet.left)->p1;  
1740                                                                                                         {
1741                                                                                                                 zzBLOCK(zztasp5);
1742                                                                                                                 zzMake0;
1743                                                                                                                 {
1744                                                                                                                 char *a;  
1745                                                                                                                 if ( (LA(1)==PassAction) ) {
1746                                                                                                                         zzmatch(PassAction);
1747                                                                                                                         
1748                                                                                                                         a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char));
1749                                                                                                                         require(a!=NULL, "rule element: cannot allocate predicate fail action");
1750                                                                                                                         strcpy(a, LATEXT(1));
1751                                                                                                                         act->pred_fail = a;
1752  zzCONSUME;
1753
1754                                                                                                                 }
1755                                                                                                                 zzEXIT(zztasp5);
1756                                                                                                                 }
1757                                                                                                         }
1758                                                                                                         if ( first_on_line) CurAltStart=(Junction *)zzaRet.left;  
1759                                                                                                         _retv = (Node *)act;  
1760                                                                                                         
1761                                                                                                         pred = computePredicateFromContextGuard(blk);
1762                                                                                                         if ( pred==NULL )
1763                                                                                                         err("invalid or missing context guard");
1764                                                                                                         else {
1765                                                                                                                 pred->expr = act->action;
1766                                                                                                                 pred->source = act;
1767                                                                                                                 act->guardpred = pred;
1768                                                                                                         }
1769                                                                                                 }
1770                                                                                                 else {
1771                                                                                                         if ( (setwd4[LA(1)]&0x2) ) {
1772                                                                                                                 zzaRet = makeBlk(zzaRet,approx);
1773                                                                                                                 FoundGuessBlk = 1;
1774                                                                                                                 ((Junction *) ((Junction *)zzaRet.left)->p1)->guess=1;
1775                                                                                                                 if ( ! first_on_line ) {
1776                                                                                                                         err("(...)? predicate must be first element of production");
1777                                                                                                                 }
1778                                                                                                         }
1779                                                                                                         else {zzFAIL(1,zzerr13,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1780                                                                                                 }
1781                                                                                                 zzEXIT(zztasp4);
1782                                                                                                 }
1783                                                                                         }
1784                                                                                 }
1785                                                                                 else {
1786                                                                                         if ( (setwd4[LA(1)]&0x4) ) {
1787                                                                                                 zzaRet = makeBlk(zzaRet,approx);  
1788                                                                                         }
1789                                                                                         else {zzFAIL(1,zzerr14,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1790                                                                                 }
1791                                                                         }
1792                                                                 }
1793                                                                 zzEXIT(zztasp3);
1794                                                                 }
1795                                                         }
1796                                                         
1797                                                         if ( pred==NULL ) {
1798                                                                 ((Junction *)((Junction *)zzaRet.left)->p1)->blockid = CurBlockID;
1799                                                                 ((Junction *)((Junction *)zzaRet.left)->p1)->tokrefs = toksrefd;
1800                                                                 ((Junction *)((Junction *)zzaRet.left)->p1)->rulerefs = rulesrefd;
1801                                                                 if (  first_on_line ) 
1802                                                                 CurAltStart = (Junction *)((Junction *)((Junction *)zzaRet.left)->p1);
1803                                                                 _retv = (Node *) ((Junction *)zzaRet.left)->p1;
1804                                                         }
1805                                                 }
1806                                                 else {
1807                                                         if ( (LA(1)==95) ) {
1808                                                                 zzmatch(95); zzCONSUME;
1809                                                                 block( &toksrefd,&rulesrefd );
1810                                                                 zzaRet = makeOpt(zzaArg(zztasp2,2),approx); --BlkLevel;  
1811                                                                 zzmatch(91);
1812                                                                 
1813                                                                 ((Junction *)((Junction *)zzaRet.left)->p1)->blockid = CurBlockID;
1814                                                                 ((Junction *)((Junction *)zzaRet.left)->p1)->tokrefs = toksrefd;
1815                                                                 ((Junction *)((Junction *)zzaRet.left)->p1)->rulerefs = rulesrefd;
1816  zzCONSUME;
1817
1818                                                                 if (  first_on_line )
1819                                                                 CurAltStart = (Junction *) ((Junction *)((Junction *)zzaRet.left)->p1);
1820                                                                 _retv = (Node *) ((Junction *)zzaRet.left)->p1;  
1821                                                         }
1822                                                         else {zzFAIL(1,zzerr15,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1823                                                 }
1824                                                 zzEXIT(zztasp2);
1825                                                 }
1826                                         }
1827                                 }
1828                                 else {
1829                                         if ( (LA(1)==118) ) {
1830                                                 zzmatch(118);
1831                                                 warn("don't you want a ')' with that '*'?"); CannotContinue=TRUE;  
1832  zzCONSUME;
1833
1834                                         }
1835                                         else {
1836                                                 if ( (LA(1)==119) ) {
1837                                                         zzmatch(119);
1838                                                         warn("don't you want a ')' with that '+'?"); CannotContinue=TRUE;  
1839  zzCONSUME;
1840
1841                                                 }
1842                                                 else {
1843                                                         if ( (LA(1)==98) ) {
1844                                                                 zzmatch(98);
1845                                                                 warn("'>' can only appear after a nonterminal"); CannotContinue=TRUE;  
1846  zzCONSUME;
1847
1848                                                         }
1849                                                         else {
1850                                                                 if ( (LA(1)==PassAction) ) {
1851                                                                         zzmatch(PassAction);
1852                                                                         warn("[...] out of context 'rule > [...]'");
1853                                                                         CannotContinue=TRUE;  
1854  zzCONSUME;
1855
1856                                                                 }
1857                                                                 else {zzFAIL(1,zzerr16,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
1858                                                         }
1859                                                 }
1860                                         }
1861                                 }
1862                         }
1863                 }
1864         }
1865         zzEXIT(zztasp1);
1866         return _retv;
1867 fail:
1868         zzEXIT(zztasp1);
1869         CannotContinue=TRUE;  
1870         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
1871         zzresynch(setwd4, 0x8);
1872         return _retv;
1873         }
1874 }
1875
1876 void
1877 #ifdef __STDC__
1878 default_exception_handler(void)
1879 #else
1880 default_exception_handler()
1881 #endif
1882 {
1883         zzRULE;
1884         zzBLOCK(zztasp1);
1885         zzMake0;
1886         {
1887          DefaultExGroup  = exception_group();
1888
1889         zzEXIT(zztasp1);
1890         return;
1891 fail:
1892         zzEXIT(zztasp1);
1893         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
1894         zzresynch(setwd4, 0x10);
1895         }
1896 }
1897
1898  ExceptionGroup * 
1899 #ifdef __STDC__
1900 exception_group(void)
1901 #else
1902 exception_group()
1903 #endif
1904 {
1905          ExceptionGroup *        _retv;
1906         PURIFY(_retv,sizeof( ExceptionGroup *   ))
1907         zzRULE;
1908         zzBLOCK(zztasp1);
1909         zzMake0;
1910         {
1911         ExceptionHandler *h; LabelEntry *label=NULL; FoundException = 1;  
1912         zzmatch(122);
1913         _retv = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));  
1914  zzCONSUME;
1915
1916         {
1917                 zzBLOCK(zztasp2);
1918                 zzMake0;
1919                 {
1920                 char *p;  
1921                 if ( (LA(1)==PassAction) ) {
1922                         zzmatch(PassAction);
1923                         
1924                         p = LATEXT(1)+1;
1925                         p[strlen(p)-1] = '\0';          /* kill trailing space */
1926                         label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1);
1927                         if ( label==NULL )
1928                         {
1929                                 err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1));
1930                         }
1931  zzCONSUME;
1932
1933                 }
1934                 zzEXIT(zztasp2);
1935                 }
1936         }
1937         {
1938                 zzBLOCK(zztasp2);
1939                 zzMake0;
1940                 {
1941                 while ( (LA(1)==124) ) {
1942                          h  = exception_handler();
1943
1944                         list_add(&(_retv->handlers), (void *)h);  
1945                         zzLOOP(zztasp2);
1946                 }
1947                 zzEXIT(zztasp2);
1948                 }
1949         }
1950         {
1951                 zzBLOCK(zztasp2);
1952                 zzMake0;
1953                 {
1954                 if ( (LA(1)==123) ) {
1955                         zzmatch(123); zzCONSUME;
1956                         zzmatch(99); zzCONSUME;
1957                         zzmatch(Action);
1958                         {
1959                                 ExceptionHandler *eh = (ExceptionHandler *)
1960                                 calloc(1, sizeof(ExceptionHandler));
1961                                 char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1962                                 require(eh!=NULL, "exception: cannot allocate handler");
1963                                 require(a!=NULL, "exception: cannot allocate action");
1964                                 strcpy(a, LATEXT(1));
1965                                 eh->action = a;
1966                                 eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char));
1967                                 require(eh->signalname!=NULL, "exception: cannot allocate sig name");
1968                                 strcpy(eh->signalname, "default");
1969                                 list_add(&(_retv->handlers), (void *)eh);
1970                         }  
1971  zzCONSUME;
1972
1973                 }
1974                 zzEXIT(zztasp2);
1975                 }
1976         }
1977         
1978         if ( label!=NULL ) {
1979                 /* Record ex group in sym tab for this label */
1980                 if ( label->ex_group!=NULL ) {
1981                         err(eMsg1("duplicate exception handler for label '%s'",label->str));
1982                 }
1983                 else {
1984                         label->ex_group = _retv;
1985                         /* Label the exception group itself */
1986                         _retv->label = label->str;
1987                         /* Make the labelled element pt to the exception also */
1988                         switch ( label->elem->ntype ) {
1989                                 case nRuleRef :
1990                                 {
1991                                         RuleRefNode *r = (RuleRefNode *)label->elem;
1992                                         r->ex_group = _retv;
1993                                         break;
1994                                 }
1995                                 case nToken :
1996                                 {
1997                                         TokNode *t = (TokNode *)label->elem;
1998                                         t->ex_group = _retv;
1999                                         break;
2000                                 }
2001                         }
2002                 }
2003                 /* You may want to remove this exc from the rule list
2004                 * and handle at the labeled element site.
2005                 */
2006                 _retv = NULL;
2007         }
2008         zzEXIT(zztasp1);
2009         return _retv;
2010 fail:
2011         zzEXIT(zztasp1);
2012         CannotContinue=TRUE;  
2013         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
2014         zzresynch(setwd4, 0x20);
2015         return _retv;
2016         }
2017 }
2018
2019  ExceptionHandler * 
2020 #ifdef __STDC__
2021 exception_handler(void)
2022 #else
2023 exception_handler()
2024 #endif
2025 {
2026          ExceptionHandler *      _retv;
2027         PURIFY(_retv,sizeof( ExceptionHandler *         ))
2028         zzRULE;
2029         zzBLOCK(zztasp1);
2030         zzMake0;
2031         {
2032         char *a;  
2033         zzmatch(124);
2034         
2035         _retv = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler));
2036         require(_retv!=NULL, "exception: cannot allocate handler");
2037  zzCONSUME;
2038
2039         {
2040                 zzBLOCK(zztasp2);
2041                 zzMake0;
2042                 {
2043                 if ( (LA(1)==NonTerminal) ) {
2044                         zzmatch(NonTerminal);
2045                         
2046                         _retv->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2047                         require(_retv->signalname!=NULL, "exception: cannot allocate sig name");
2048                         strcpy(_retv->signalname, LATEXT(1));
2049  zzCONSUME;
2050
2051                 }
2052                 else {
2053                         if ( (LA(1)==TokenTerm) ) {
2054                                 zzmatch(TokenTerm);
2055                                 
2056                                 _retv->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2057                                 require(_retv->signalname!=NULL, "exception: cannot allocate sig name");
2058                                 strcpy(_retv->signalname, LATEXT(1));
2059  zzCONSUME;
2060
2061                         }
2062                         else {zzFAIL(1,zzerr17,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
2063                 }
2064                 zzEXIT(zztasp2);
2065                 }
2066         }
2067         zzmatch(99); zzCONSUME;
2068         {
2069                 zzBLOCK(zztasp2);
2070                 zzMake0;
2071                 {
2072                 _retv->action = NULL;  
2073                 if ( (LA(1)==Action) ) {
2074                         zzmatch(Action);
2075                         
2076                         _retv->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
2077                         require(_retv->action!=NULL, "exception: cannot allocate action");
2078                         strcpy(_retv->action, LATEXT(1));
2079  zzCONSUME;
2080
2081                 }
2082                 zzEXIT(zztasp2);
2083                 }
2084         }
2085         zzEXIT(zztasp1);
2086         return _retv;
2087 fail:
2088         zzEXIT(zztasp1);
2089         CannotContinue=TRUE;  
2090         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
2091         zzresynch(setwd4, 0x40);
2092         return _retv;
2093         }
2094 }
2095
2096 void
2097 #ifdef __STDC__
2098 enum_file( char *fname )
2099 #else
2100 enum_file(fname)
2101  char *fname ;
2102 #endif
2103 {
2104         zzRULE;
2105         zzBLOCK(zztasp1);
2106         zzMake0;
2107         {
2108         if ( (setwd4[LA(1)]&0x80) ) {
2109                 {
2110                         zzBLOCK(zztasp2);
2111                         zzMake0;
2112                         {
2113                         if ( (LA(1)==132) ) {
2114                                 zzmatch(132); zzCONSUME;
2115                                 zzmatch(ID); zzCONSUME;
2116                                 {
2117                                         zzBLOCK(zztasp3);
2118                                         zzMake0;
2119                                         {
2120                                         if ( (LA(1)==138) ) {
2121                                                 zzmatch(138); zzCONSUME;
2122                                                 zzmatch(ID); zzCONSUME;
2123                                         }
2124                                         zzEXIT(zztasp3);
2125                                         }
2126                                 }
2127                         }
2128                         zzEXIT(zztasp2);
2129                         }
2130                 }
2131                 {
2132                         zzBLOCK(zztasp2);
2133                         zzMake0;
2134                         {
2135                         if ( (LA(1)==140) ) {
2136                                 {
2137                                         zzBLOCK(zztasp3);
2138                                         int zzcnt=1;
2139                                         zzMake0;
2140                                         {
2141                                         do {
2142                                                 enum_def(  fname );
2143                                                 zzLOOP(zztasp3);
2144                                         } while ( (LA(1)==140) );
2145                                         zzEXIT(zztasp3);
2146                                         }
2147                                 }
2148                         }
2149                         else {
2150                                 if ( (LA(1)==138) ) {
2151                                         defines(  fname );
2152                                 }
2153                                 else {zzFAIL(1,zzerr18,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
2154                         }
2155                         zzEXIT(zztasp2);
2156                         }
2157                 }
2158         }
2159         else {
2160                 if ( (LA(1)==Eof) ) {
2161                 }
2162                 else {zzFAIL(1,zzerr19,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
2163         }
2164         zzEXIT(zztasp1);
2165         return;
2166 fail:
2167         zzEXIT(zztasp1);
2168         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
2169         zzresynch(setwd5, 0x1);
2170         }
2171 }
2172
2173 void
2174 #ifdef __STDC__
2175 defines( char *fname )
2176 #else
2177 defines(fname)
2178  char *fname ;
2179 #endif
2180 {
2181         zzRULE;
2182         zzBLOCK(zztasp1);
2183         zzMake0;
2184         {
2185         int v,maxt= -1; char *t;  
2186         {
2187                 zzBLOCK(zztasp2);
2188                 int zzcnt=1;
2189                 zzMake0;
2190                 {
2191                 do {
2192                         zzmatch(138); zzCONSUME;
2193                         zzmatch(ID);
2194                         t = mystrdup(LATEXT(1));  
2195  zzCONSUME;
2196
2197                         zzmatch(INT);
2198                         
2199                         v = atoi(LATEXT(1));
2200                         /*                      fprintf(stderr, "#token %s=%d\n", t, v);*/
2201                         TokenNum = v;
2202                         if ( v>maxt ) maxt=v;
2203                         if ( Tnum( t ) == 0 ) addForcedTname( t, v );
2204                         else {
2205                                 warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline);
2206                         }
2207  zzCONSUME;
2208
2209                         zzLOOP(zztasp2);
2210                 } while ( (LA(1)==138) );
2211                 zzEXIT(zztasp2);
2212                 }
2213         }
2214         TokenNum = maxt + 1;  
2215         zzEXIT(zztasp1);
2216         return;
2217 fail:
2218         zzEXIT(zztasp1);
2219         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
2220         zzresynch(setwd5, 0x2);
2221         }
2222 }
2223
2224 void
2225 #ifdef __STDC__
2226 enum_def( char *fname )
2227 #else
2228 enum_def(fname)
2229  char *fname ;
2230 #endif
2231 {
2232         zzRULE;
2233         zzBLOCK(zztasp1);
2234         zzMake0;
2235         {
2236         int v= 0; char *t;  
2237         zzmatch(140); zzCONSUME;
2238         zzmatch(ID); zzCONSUME;
2239         zzmatch(141); zzCONSUME;
2240         zzmatch(ID);
2241         t = mystrdup(LATEXT(1));  
2242  zzCONSUME;
2243
2244         {
2245                 zzBLOCK(zztasp2);
2246                 zzMake0;
2247                 {
2248                 if ( (LA(1)==142) ) {
2249                         zzmatch(142); zzCONSUME;
2250                         zzmatch(INT);
2251                         v=atoi(LATEXT(1));  
2252  zzCONSUME;
2253
2254                 }
2255                 else {
2256                         if ( (setwd5[LA(1)]&0x4) ) {
2257                                 v++;  
2258                         }
2259                         else {zzFAIL(1,zzerr20,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
2260                 }
2261                 zzEXIT(zztasp2);
2262                 }
2263         }
2264         
2265         /*                      fprintf(stderr, "#token %s=%d\n", t, v);*/
2266         TokenNum = v;
2267         if ( Tnum( t ) == 0 ) addForcedTname( t, v );
2268         else {
2269                 warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline);
2270         }
2271         {
2272                 zzBLOCK(zztasp2);
2273                 zzMake0;
2274                 {
2275                 while ( (LA(1)==143) ) {
2276                         zzmatch(143); zzCONSUME;
2277                         {
2278                                 zzBLOCK(zztasp3);
2279                                 zzMake0;
2280                                 {
2281                                 if ( (LA(1)==ID) ) {
2282                                         zzmatch(ID);
2283                                         t = mystrdup(LATEXT(1));  
2284  zzCONSUME;
2285
2286                                         {
2287                                                 zzBLOCK(zztasp4);
2288                                                 zzMake0;
2289                                                 {
2290                                                 if ( (LA(1)==142) ) {
2291                                                         zzmatch(142); zzCONSUME;
2292                                                         zzmatch(INT);
2293                                                         v=atoi(LATEXT(1));  
2294  zzCONSUME;
2295
2296                                                 }
2297                                                 else {
2298                                                         if ( (setwd5[LA(1)]&0x8) ) {
2299                                                                 v++;  
2300                                                         }
2301                                                         else {zzFAIL(1,zzerr21,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
2302                                                 }
2303                                                 zzEXIT(zztasp4);
2304                                                 }
2305                                         }
2306                                         
2307                                         /*                                      fprintf(stderr, "#token %s=%d\n", t, v);*/
2308                                         TokenNum = v;
2309                                         if ( Tnum( t ) == 0 ) addForcedTname( t, v );
2310                                         else {
2311                                                 warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline);
2312                                         }
2313                                 }
2314                                 zzEXIT(zztasp3);
2315                                 }
2316                         }
2317                         zzLOOP(zztasp2);
2318                 }
2319                 zzEXIT(zztasp2);
2320                 }
2321         }
2322         zzmatch(144); zzCONSUME;
2323         zzmatch(145);
2324         TokenNum++;  
2325  zzCONSUME;
2326
2327         zzEXIT(zztasp1);
2328         return;
2329 fail:
2330         zzEXIT(zztasp1);
2331         zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
2332         zzresynch(setwd5, 0x10);
2333         }
2334 }
2335
2336 /* semantics of #token */
2337 static void
2338 #ifdef __STDC__
2339 chkToken(char *t, char *e, char *a, int tnum)
2340 #else
2341 chkToken(t,e,a,tnum)
2342 char *t, *e, *a;
2343 int tnum;
2344 #endif
2345 {
2346         TermEntry *p;
2347         
2348         /* check to see that they don't try to redefine a token as a token class */
2349         if ( t!=NULL ) {
2350         p = (TermEntry *) hash_get(Tname, t);
2351         if ( p!=NULL && p->classname ) {
2352         err(eMsg1("redefinition of #tokclass '%s' to #token not allowed; ignored",t));
2353         if ( a!=NULL ) free((char *)a);
2354         return;
2355 }
2356 }
2357
2358         if ( t==NULL && e==NULL ) {                     /* none found */
2359 err("#token requires at least token name or rexpr");
2360 }
2361 else if ( t!=NULL && e!=NULL ) {        /* both found */
2362 if ( UserDefdTokens ) {                 /* if #tokdefs, must not define new */
2363 p = (TermEntry *) hash_get(Tname, t);
2364 if ( p==NULL ) {
2365 err(eMsg1("#token definition '%s' not allowed with #tokdefs; ignored",t));
2366 return;
2367 }
2368 }
2369 Tklink(t, e);
2370 if ( a!=NULL ) {
2371 if ( hasAction(e) ) {
2372 err(eMsg1("redefinition of action for %s; ignored",e));
2373 }
2374 else setHasAction(e, a);
2375 }
2376 }
2377 else if ( t!=NULL ) {                           /* only one found */
2378 if ( UserDefdTokens ) {
2379 err(eMsg1("#token definition '%s' not allowed with #tokdefs; ignored",t));
2380 return;
2381 }
2382 if ( Tnum( t ) == 0 ) addTname( t );
2383 else {
2384 err(eMsg1("redefinition of token %s; ignored",t));
2385 }
2386 if ( a!=NULL ) {
2387 err(eMsg1("action cannot be attached to a token name (%s); ignored",t));
2388 free((char *)a);
2389 }
2390 }
2391 else if ( e!=NULL ) {
2392 if ( Tnum( e ) == 0 ) addTexpr( e );
2393 else {
2394 if ( hasAction(e) ) {
2395 err(eMsg1("redefinition of action for expr %s; ignored",e));
2396 }
2397 else if ( a==NULL ) {
2398 err(eMsg1("redefinition of expr %s; ignored",e));
2399 }
2400 }
2401 if ( a!=NULL ) setHasAction(e, a);
2402 }
2403
2404         /* if a token type number was specified, then add the token ID and 'tnum'
2405 * pair to the ForcedTokens list.  (only applies if an id was given)
2406 */
2407 if ( t!=NULL && tnum>0 )
2408 {
2409 if ( set_el(tnum, reserved_positions) )
2410 {
2411 err(eMsgd("a token has already been forced to token number %d; ignored", tnum));
2412 }
2413 else
2414 {
2415 list_add(&ForcedTokens, newForcedToken(t,tnum));
2416 set_orel(tnum, &reserved_positions);
2417 }
2418 }
2419 }
2420
2421 static int
2422 #ifdef __USE_PROTOS
2423 match_token(char *s, char **nxt)
2424 #else
2425 match_token(s,nxt)
2426 char *s;
2427 char **nxt;
2428 #endif
2429 {
2430         if ( !(*s>='A' && *s<='Z') ) return 0;
2431         s++;
2432         while ( (*s>='a' && *s<='z') ||
2433         (*s>='A' && *s<='Z') ||
2434         (*s>='0' && *s<='9') ||
2435         *s=='_' )
2436         {
2437                 s++;
2438         }
2439         if ( *s!=' ' && *s!='}' ) return 0;
2440         *nxt = s;
2441         return 1;
2442 }
2443
2444 static int
2445 #ifdef __USE_PROTOS
2446 match_rexpr(char *s, char **nxt)
2447 #else
2448 match_rexpr(s,nxt)
2449 char *s;
2450 char **nxt;
2451 #endif
2452 {
2453         if ( *s!='"' ) return 0;
2454         s++;
2455         while ( *s!='"' )
2456         {
2457                 if ( *s=='\n' )
2458                 warn("eoln found in regular expression");
2459                 if ( *s=='\\' ) s++;
2460                 s++;
2461         }
2462         *nxt = s+1;
2463         return 1;
2464 }
2465
2466 /*
2467 * Walk a string "{ A .. Z }" where A..Z is a space separated list
2468 * of token references (either labels or reg exprs).  Return a
2469 * string "inlineX_set" for some unique integer X.  Basically,
2470 * we pretend as if we had seen "#tokclass inlineX { A .. Z }"
2471 * on the input stream outside of an action.
2472 */
2473 char *
2474 #ifdef __USE_PROTOS
2475 inline_set(char *s)
2476 #else
2477 inline_set(s)
2478 char *s;
2479 #endif
2480 {
2481         char *nxt;
2482         fprintf(stderr, "found consumeUntil( {...} )\n");
2483         while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
2484         if ( *s!='{' )
2485         {
2486                 err("malformed consumeUntil( {...} ); missing '{'");
2487                 return "bad_set";
2488         }
2489         s++;
2490         while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
2491         while ( *s!='}' )
2492         {
2493                 if ( match_token(s,&nxt) ) fprintf(stderr, "found token %s\n", s);
2494                 else if ( match_rexpr(s,&nxt) ) fprintf(stderr, "found rexpr %s\n", s);
2495                 else {
2496                         err("invalid element in consumeUntil( {...} )");
2497                         return "bad_set";
2498                 }
2499                 s = nxt;
2500                 while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
2501         }
2502         return "inlineX_set";
2503 }
2504
2505 /* ANTLR-specific syntax error message generator
2506 * (define USER_ZZSYN when compiling so don't get 2 definitions)
2507 */
2508 void
2509 #ifdef __STDC__
2510 zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok,  
2511 int k, char *bad_text)
2512 #else
2513 zzsyn(text, tok, egroup, eset, etok, k, bad_text)
2514 char *text, *egroup, *bad_text;
2515 int tok;
2516 int etok;
2517 int k;
2518 SetWordType *eset;
2519 #endif
2520 {
2521 fprintf(stderr, ErrHdr, FileStr[CurFile]!=NULL?FileStr[CurFile]:"stdin", zzline);
2522 fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text);
2523 if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
2524 if ( k==1 ) fprintf(stderr, " missing");
2525 else
2526 {
2527 fprintf(stderr, "; \"%s\" not", bad_text);
2528 if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
2529 }
2530 if ( zzset_deg(eset)>0 ) zzedecode(eset);
2531 else fprintf(stderr, " %s", zztokens[etok]);
2532 if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup);
2533 fprintf(stderr, "\n");
2534 }