]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CodeTools/TianoTools/Pccts/antlr/bits.c
ddd9bd6053dd510e8d0fbda3fb98dc7f10aa7891
1 /* bits.c -- manage creation and output of bit sets used by the parser.
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
7 * company may do whatever they wish with source code distributed with
8 * PCCTS or the code generated by PCCTS, including the incorporation of
9 * PCCTS, or its output, into commerical software.
11 * We encourage users to develop software with PCCTS. However, we do ask
12 * that credit is given to us for developing PCCTS. By "credit",
13 * we mean that if you incorporate our source code into one of your
14 * programs (commercial product, research project, or otherwise) that you
15 * acknowledge this fact somewhere in the documentation, research report,
16 * etc... If you like PCCTS and have developed a nice tool with the
17 * output, please mention that you developed it using PCCTS. In
18 * addition, we ask that this header remain intact in our source code.
19 * As long as these guidelines are kept, we expect to continue enhancing
20 * this system and expect to make other tools available as they are
25 * Parr Research Corporation
26 * with Purdue University and AHPCRC, University of Minnesota
41 /* char is only thing that is pretty much always known == 8 bits
42 * This allows output of antlr (set stuff, anyway) to be androgynous (portable)
44 typedef unsigned char SetWordType
;
46 #define BitsPerWord BitsPerByte*sizeof(SetWordType)
48 static SetWordType
*setwd
= NULL
;
54 /* Used to convert native wordsize, which ANTLR uses (via set.c) to manipulate sets,
55 to bytes that are most portable size-wise.
59 DumpIntAsChars( FILE *f
, char *format
, unsigned wd
)
61 DumpIntAsChars( f
, format
, wd
)
68 /* uses max of 32 bit unsigned integer for the moment */
69 static unsigned long byte_mask
[sizeof(unsigned long)] =
70 { 0xFF, 0xFF00UL
, 0xFF0000UL
, 0xFF000000UL
}; /* MR20 G. Hobbelt */
71 /* 0xFF00000000, 0xFF0000000000, 0xFF000000000000, 0xFF00000000000000 };*/
73 /* for each byte in the word */
74 assert(sizeof(unsigned) <= 4); /* M20 G. Hobbelt Sanity check */
75 for (i
=0; i
<sizeof(unsigned); i
++)
77 /* mask out the ith byte and shift down to the first 8 bits */
78 fprintf(f
, format
, (wd
&byte_mask
[i
])>>(i
*BitsPerByte
));
79 if ( i
<sizeof(unsigned)-1) fprintf(f
, ",");
83 /* Create a new setwd (ignoring [Ep] token on end) */
95 setwd
= (SetWordType
*) calloc(TokenNum
, sizeof(SetWordType
));
96 require(setwd
!=NULL
, "NewSetWd: cannot alloc set wd\n");
98 for (p
= setwd
; p
<&(setwd
[TokenNum
]); p
++) {*p
=0;}
109 if ( GenCC
) DumpSetWdForCC();
110 else DumpSetWdForC();
113 /* Dump the current setwd to ErrFile. 0..MaxTokenVal */
116 DumpSetWdForC( void )
123 if ( setwd
==NULL
) return;
124 fprintf(DefFile
, "extern SetWordType setwd%d[];\n", wordnum
);
126 "SetWordType setwd%d[%d] = {", wordnum
, TokenNum
-1);
127 for (i
=0; i
<TokenNum
-1; i
++)
130 if ( i
!=0 ) fprintf(ErrFile
, ",");
131 if ( c
== 8 ) {fprintf(ErrFile
, "\n\t"); c
=1;} else c
++;
132 fprintf(ErrFile
, "0x%x", setwd
[i
]);
134 fprintf(ErrFile
, "};\n");
137 /* Dump the current setwd to Parser.C file. 0..MaxTokenVal;
138 * Only used if -CC on.
142 DumpSetWdForCC( void )
149 if ( setwd
==NULL
) return;
150 fprintf(Parser_h
, "\tstatic SetWordType setwd%d[%d];\n", wordnum
, TokenNum
-1);
152 "SetWordType %s::setwd%d[%d] = {", CurrentClassName
, wordnum
,
154 for (i
=0; i
<TokenNum
-1; i
++)
157 if ( i
!=0 ) fprintf(Parser_c
, ",");
158 if ( c
== 8 ) {fprintf(Parser_c
, "\n\t"); c
=1;} else c
++;
159 fprintf(Parser_c
, "0x%x", setwd
[i
]);
161 fprintf(Parser_c
, "};\n");
164 /* Make a new set. Dump old setwd and create new setwd if current setwd is full */
173 if ( setnum
==BitsPerWord
) /* is current setwd full? */
175 DumpSetWd(); NewSetWd(); setnum
= 0;
179 /* s is a set of tokens. Turn on bit at each token position in set 'setnum' */
188 SetWordType mask
=(((unsigned)1)<<setnum
);
191 while ( !set_nil(s
) )
199 /* E r r o r C l a s s S t u f f */
201 /* compute the FIRST of a rule for the error class stuff */
204 Efirst( char *rule
, ECnode
*eclass
)
206 Efirst( rule
, eclass
)
213 RuleEntry
*q
= (RuleEntry
*) hash_get(Rname
, rule
);
217 warnNoFL(eMsg2("undefined rule '%s' referenced in errclass '%s'; ignored",
218 rule
, TokenString(eclass
->tok
)));
221 r
= RulePtr
[q
->rulenum
];
222 r
->end
->halt
= TRUE
; /* don't let reach fall off end of rule here */
225 r
->end
->halt
= FALSE
;
230 * scan the list of tokens/eclasses/nonterminals filling the new eclass
231 * with the set described by the list. Note that an eclass can be
232 * quoted to allow spaces etc... However, an eclass must not conflict
233 * with a reg expr found elsewhere. The reg expr will be taken over
238 doEclass( char *eclass
)
251 require(eclass
!=NULL
, "doEclass: NULL eset");
253 p
= (ECnode
*) eclass
;
254 lexmode(p
->lexclass
); /* switch to lexclass where errclass is defined */
256 for (e
= (p
->elist
)->next
; e
!=NULL
; e
=e
->next
)
260 if ( islower( *((char *)e
->elem
) ) ) /* is it a rule ref? (alias FIRST request) */
262 a
= Efirst((char *)e
->elem
, p
);
263 set_orin(&p
->eset
, a
);
268 else if ( *((char *)e
->elem
)=='"' )
271 q
= (TermEntry
*) hash_get(Texpr
, (char *) e
->elem
);
274 /* if quoted and not an expr look for eclass name */
275 q
= (TermEntry
*) hash_get(Tname
, *((char **)&(e
->elem
))=StripQuotes((char *)e
->elem
));
276 if ( q
!= NULL
) t
= q
->token
;
280 else /* labelled token/eclass/tokclass */
282 q
= (TermEntry
*) hash_get(Tname
, (char *)e
->elem
);
285 if ( strcmp((char *)e
->elem
, TokenString(p
->tok
))==0 )
287 warnNoFL(eMsg1("self-referential error class '%s'; ignored",
298 if (isTermEntryTokClass(q
)) { /* MR23 */
299 tcnode
= q
->tclass
; /* MR23 */
300 set_orin(&p
->eset
, tcnode
->tset
); /* MR23 */
301 deg
= set_deg(p
->eset
); /* MR23 */
304 set_orel(t
, &p
->eset
);
308 else warnNoFL(eMsg2("undefined token '%s' referenced in errclass '%s'; ignored",
309 (char *)e
->elem
, TokenString(p
->tok
)));
316 ComputeErrorSets( void )
322 list_apply(eclasses
, (void (*)(void *)) doEclass
);
325 list_apply(eclasses
, (void (*)(void *)) doEclass
);
327 list_apply(eclasses
, doEclass
);
334 ComputeTokSets( void )
339 ListNode
*t
, *e
= NULL
, *e1
, *e2
;
340 int something_changed
;
343 TermEntry
*q
, *q1
, *q2
;
345 if ( tclasses
== NULL
) return;
347 /* turn lists of token/tokclass references into sets */
348 for (t
= tclasses
->next
; t
!=NULL
; t
=t
->next
)
350 p
= (TCnode
*) t
->elem
;
352 /* if wild card, then won't have entries in tclass, assume all_tokens */
353 if ( p
->tok
== WildCardToken
)
355 p
->tset
= set_dup(all_tokens
);
359 lexmode(p
->lexclass
); /* switch to lexclass where tokclass is defined */
362 /* instantiate all tokens/token_classes into the tset */
363 for (e
= (p
->tlist
)->next
; e
!=NULL
; e
=e
->next
)
366 tokstr
= (char *)e
->elem
;
367 if ( *tokstr
== '"' ) {
368 q
= (TermEntry
*) hash_get(Texpr
, tokstr
);
369 require(q
!=NULL
, "ComputeTokSets: no token def");
370 set_orel(q
->token
, &p
->tset
);
371 } else if (tokstr
[0] == '.') {
375 q1
= (TermEntry
*) hash_get(Tname
, (char *)e1
->elem
);
376 require(q1
!=NULL
, "ComputeTokSets: no token def");
377 q2
= (TermEntry
*) hash_get(Tname
, (char *)e2
->elem
);
378 require(q2
!=NULL
, "ComputeTokSets: no token def");
380 if (set_el(q1
->token
,imag_tokens
)) {
381 errNoFL(eMsg2("can't define #tokclass %s using #tokclass or #errclass %s",
382 TokenString(p
->tok
),(char *)e1
->elem
) );
384 if (set_el(q2
->token
,imag_tokens
)) {
385 errNoFL(eMsg2("can't define #tokclass %s using #tokclass or #errclass %s",
386 TokenString(p
->tok
),(char *)e2
->elem
) );
388 if (q1
->token
> q2
->token
) {
389 errNoFL(eMsg3("for #tokclass %s %s..%s - first token number > second token number",
390 TokenString(p
->tok
),(char *)e1
->elem
,(char *)e2
->elem
) );
391 for (i
=q2
->token
; i
<=q1
->token
; i
++) { set_orel(i
, &p
->tset
); }
393 for (i
=q1
->token
; i
<=q2
->token
; i
++) { set_orel(i
, &p
->tset
); }
396 q
= (TermEntry
*) hash_get(Tname
, tokstr
);
397 require(q
!=NULL
, "ComputeTokSets: no token def");
398 set_orel(q
->token
, &p
->tset
);
403 /* Go thru list of tokclasses again looking for tokclasses in sets */
405 something_changed
= 0;
406 for (t
= tclasses
->next
; t
!=NULL
; t
=t
->next
)
409 p
= (TCnode
*) t
->elem
;
410 tcl
= set_and(p
->tset
, tokclasses
);
414 /* replace refs to tokclasses with the associated set of tokens */
415 something_changed
= 1;
416 while ( !set_nil(tcl
) )
418 tk
= set_int(tcl
); /* grab one of the tok class refs */
420 if ( p
->tok
!= tk
) /* tokclass ref to yourself? */
422 q
= (TermEntry
*) hash_get(Tname
, TokenString(tk
));
423 require(q
!=NULL
, "#tokclass not in hash table");
424 set_orin(&p
->tset
, q
->tclass
->tset
);
426 set_rm(tk
, p
->tset
); /* remove ref that we replaced */
431 if ( something_changed
) goto again
;
436 DumpRemainingTokSets(void)
438 DumpRemainingTokSets()
444 /* Go thru tclasses (for the last time) and dump the sets not dumped
445 * during code gen; yes, this is a bogus way to do this, but ComputeTokSets()
446 * can't dump the defs as the error file and tok file has not been created
449 if ( tclasses
==NULL
) return;
450 for (t
= tclasses
->next
; t
!=NULL
; t
=t
->next
)
453 p
= (TCnode
*) t
->elem
;
454 if ( p
->dumped
) continue;
455 e
= DefErrSet(&(p
->tset
), 0, TokenString(p
->tok
));
462 /* replace a subset of an error set with an error class name if a subset is found
463 * repeat process until no replacements made
467 SubstErrorClass( set
*f
)
475 ECnode
*ec
, *maxclass
= NULL
;
477 require(f
!=NULL
, "SubstErrorClass: NULL eset");
479 if ( eclasses
== NULL
) return;
484 for (p
=eclasses
->next
; p
!=NULL
; p
=p
->next
) /* chk all error classes */
486 ec
= (ECnode
*) p
->elem
;
487 if ( ec
->setdeg
> max
)
489 if ( set_sub(ec
->eset
, *f
) || set_equ(ec
->eset
, *f
) )
490 {maxclass
= ec
; max
=ec
->setdeg
;}
493 if ( maxclass
!= NULL
) /* if subset found, replace with token */
495 a
= set_dif(*f
, maxclass
->eset
);
496 set_orel((unsigned)maxclass
->tok
, &a
);
506 DefErrSet1(int nilOK
, set
*f
, int subst
, char *name
)
508 DefErrSet1(nilOK
, f
, subst
, name
)
511 int subst
; /* should be substitute error classes? */
515 if ( GenCC
) return DefErrSetForCC1(nilOK
, f
, subst
, name
, "_set");
516 else return DefErrSetForC1(nilOK
, f
, subst
, name
, "_set");
521 DefErrSet( set
*f
, int subst
, char *name
)
523 DefErrSet( f
, subst
, name
)
525 int subst
; /* should be substitute error classes? */
529 return DefErrSet1(0,f
,subst
,name
);
534 DefErrSetWithSuffix(int nilOK
, set
*f
, int subst
, char *name
, const char* suffix
)
536 DefErrSetWithSuffix(nilOK
, f
, subst
, name
, suffix
)
539 int subst
; /* should be substitute error classes? */
544 if ( GenCC
) return DefErrSetForCC1(nilOK
, f
, subst
, name
, suffix
);
545 else return DefErrSetForC1(nilOK
, f
, subst
, name
, suffix
);
548 /* Define a new error set. WARNING...set-implementation dependent.
552 DefErrSetForC1(int nilOK
, set
*f
, int subst
, char * name
, const char * suffix
)
554 DefErrSetForC1(nilOK
, f
, subst
, name
, suffix
)
555 int nilOK
; /* MR13 */
557 int subst
; /* should be substitute error classes? */
565 if (!nilOK
) require(!set_nil(*f
), "DefErrSetForC1: nil set to dump?");
567 if ( subst
) SubstErrorClass(f
);
569 endp
= &(f
->setword
[f
->n
]);
572 fprintf(DefFile
, "extern SetWordType %s%s[];\n", name
, suffix
);
574 fprintf(DefFile
, "extern SetWordType zzerr%d[];\n", esetnum
);
576 fprintf(ErrFile
, "SetWordType %s%s[%d] = {",
579 NumWords(TokenNum
-1)*sizeof(unsigned));
582 fprintf(ErrFile
, "SetWordType zzerr%d[%d] = {",
584 NumWords(TokenNum
-1)*sizeof(unsigned));
588 if ( e
> 1 ) fprintf(ErrFile
, ", ");
589 DumpIntAsChars(ErrFile
, "0x%x", *p
++);
593 if ( p
< endp
) fprintf(ErrFile
, ",");
594 fprintf(ErrFile
, "\n\t");
599 fprintf(ErrFile
, "};\n");
606 DefErrSetForC( set
*f
, int subst
, char *name
)
608 DefErrSetForC( f
, subst
, name
)
610 int subst
; /* should be substitute error classes? */
614 return DefErrSetForC1(0,f
,subst
,name
, "_set");
617 /* Define a new error set. WARNING...set-implementation dependent;
618 * Only used when -CC on.
623 DefErrSetForCC1(int nilOK
, set
*f
, int subst
, char *name
, const char *suffix
)
625 DefErrSetForCC1(nilOK
, f
, subst
, name
, suffix
)
626 int nilOK
; /* MR13 */
628 int subst
; /* should be substitute error classes? */
636 if (!nilOK
) require(!set_nil(*f
), "DefErrSetForCC1: nil set to dump?");
638 if ( subst
) SubstErrorClass(f
);
640 endp
= &(f
->setword
[f
->n
]);
644 fprintf(Parser_h
, "\tstatic SetWordType %s%s[%d];\n", name
, suffix
,
645 NumWords(TokenNum
-1)*sizeof(unsigned));
646 fprintf(Parser_c
, "SetWordType %s::%s%s[%d] = {",
650 NumWords(TokenNum
-1)*sizeof(unsigned));
653 fprintf(Parser_c
, "SetWordType %s::err%d[%d] = {",
656 NumWords(TokenNum
-1)*sizeof(unsigned));
657 fprintf(Parser_h
, "\tstatic SetWordType err%d[%d];\n", esetnum
,
658 NumWords(TokenNum
-1)*sizeof(unsigned));
663 if ( e
> 1 ) fprintf(Parser_c
, ", ");
664 DumpIntAsChars(Parser_c
, "0x%x", *p
++);
667 if ( p
< endp
) fprintf(Parser_c
, ",");
668 fprintf(Parser_c
, "\n\t");
673 fprintf(Parser_c
, "};\n");
680 DefErrSetForCC( set
*f
, int subst
, char *name
)
682 DefErrSetForCC( f
, subst
, name
)
684 int subst
; /* should be substitute error classes? */
688 return DefErrSetForCC1(0,f
,subst
,name
, "_set");
693 GenParser_c_Hdr(void)
700 char * hasAkaName
= NULL
; /* MR23 */
702 hasAkaName
= (char *) malloc(TokenNum
+1); /* MR23 */
703 require(hasAkaName
!=NULL
, "Cannot alloc hasAkaName\n"); /* MR23 */
704 for (i
= 0; i
< TokenNum
; i
++) hasAkaName
[i
]='0'; /* MR23 */
705 hasAkaName
[TokenNum
] = 0; /* MR23 */
707 fprintf(Parser_c
, "/*\n");
708 fprintf(Parser_c
, " * %s: P a r s e r S u p p o r t\n", CurrentClassName
);
709 fprintf(Parser_c
, " *\n");
710 fprintf(Parser_c
, " * Generated from:");
711 for (i
=0; i
<NumFiles
; i
++) fprintf(Parser_c
, " %s", FileStr
[i
]);
712 fprintf(Parser_c
, "\n");
713 fprintf(Parser_c
, " *\n");
714 fprintf(Parser_c
, " * Terence Parr, Russell Quong, Will Cohen, and Hank Dietz: 1989-2001\n");
715 fprintf(Parser_c
, " * Parr Research Corporation\n");
716 fprintf(Parser_c
, " * with Purdue University Electrical Engineering\n");
717 fprintf(Parser_c
, " * with AHPCRC, University of Minnesota\n");
718 fprintf(Parser_c
, " * ANTLR Version %s\n", Version
);
719 fprintf(Parser_c
, " */\n\n");
721 if ( FirstAction
!= NULL
) dumpAction(FirstAction
,Parser_c
, 0, -1, 0, 1); /* MR11 MR15b */
723 fprintf(Parser_c
, "#define ANTLR_VERSION %s\n", VersionDef
);
725 fprintf(Parser_c
, "#include \"pcctscfg.h\"\n");
726 fprintf(Parser_c
, "#include \"pccts_stdio.h\"\n");
727 fprintf(Parser_c
, "#define ANTLR_SUPPORT_CODE\n");
728 if ( UserTokenDefsFile
!= NULL
)
729 fprintf(Parser_c
, "#include %s\n", UserTokenDefsFile
);
731 fprintf(Parser_c
, "#include \"%s\"\n", DefFileName
);
733 fprintf(Parser_c
, "#include \"%s.h\"\n\n", CurrentClassName
);
735 fprintf(Parser_c
, "const ANTLRChar *%s::tokenName(int tok) ", /* MR1 */
736 CurrentClassName
); /* MR1 */
737 fprintf(Parser_c
, " { return _token_tbl[tok]; }\n"); /* MR1 */ /* MR10 */
738 /* Dump a Parser::tokens for each automaton */
739 fprintf(Parser_c
, "\nconst ANTLRChar *%s::_token_tbl[]={\n",
740 CurrentClassName
); /* MR20 */
741 fprintf(Parser_c
, "\t/* 00 */\t\"Invalid\"");
743 for (i
=1; i
<TokenNum
-1; i
++)
746 if ( i
== EpToken
) continue;
747 /* remapped to invalid token? */
748 if ( TokenInd
!=NULL
&& TokenInd
[i
]>=LastTokenCounted
)
750 fprintf(Parser_c
, ",\n\t/* %02d */\t\"invalid\"", i
);
753 if ( TokenString(i
) != NULL
) {
754 te
=(TermEntry
*) hash_get(Tname
,TokenString(i
)); /* MR11 */
755 if (te
== NULL
|| te
->akaString
== NULL
) { /* MR11 */
756 fprintf(Parser_c
, ",\n\t/* %02d */\t\"%s\"", i
, TokenString(i
));
758 hasAkaName
[i
] = '1'; /* MR23 */
759 fprintf(Parser_c
, ",\n\t/* %02d */\t\"%s\"", i
, te
->akaString
); /* MR11 */
764 /* look in all lexclasses for the reg expr */
765 for (j
=0; j
<NumLexClasses
; j
++)
768 if ( ExprString(i
) != NULL
)
770 fprintf(Parser_c
, ",\n\t/* %02d */\t", i
);
771 dumpExpr(Parser_c
, ExprString(i
));
775 if ( j
>=NumLexClasses
)
777 if ( UserDefdTokens
)
779 fprintf(Parser_c
, ",\n\t/* %02d */\t\"\"", i
);
782 fatal_internal(eMsgd("No label or expr for token %d",i
));
786 fprintf(Parser_c
, "\n};\n");
788 /* Build constructors */
789 fprintf(Parser_c
, "\n%s::", CurrentClassName
);
790 fprintf(Parser_c
, "%s(ANTLRTokenBuffer *input) : %s(input,%d,%d,%d,%d)\n",
792 (BaseClassName
== NULL
? "ANTLRParser" : BaseClassName
),
796 NumWords(TokenNum
-1)*sizeof(unsigned));
797 fprintf(Parser_c
, "{\n");
798 fprintf(Parser_c
, "\ttoken_tbl = _token_tbl;\n");
800 fprintf(Parser_c
, "\ttraceOptionValueDefault=1;\t\t// MR10 turn trace ON\n");
802 fprintf(Parser_c
, "\ttraceOptionValueDefault=0;\t\t// MR10 turn trace OFF\n");
804 fprintf(Parser_c
, "}\n\n");
805 free ( (void *) hasAkaName
);
810 GenParser_h_Hdr(void)
817 fprintf(Parser_h
, "/*\n");
818 fprintf(Parser_h
, " * %s: P a r s e r H e a d e r \n", CurrentClassName
);
819 fprintf(Parser_h
, " *\n");
820 fprintf(Parser_h
, " * Generated from:");
821 for (i
=0; i
<NumFiles
; i
++) fprintf(Parser_h
, " %s", FileStr
[i
]);
822 fprintf(Parser_h
, "\n");
823 fprintf(Parser_h
, " *\n");
824 fprintf(Parser_h
, " * Terence Parr, Russell Quong, Will Cohen, and Hank Dietz: 1989-2001\n");
825 fprintf(Parser_h
, " * Parr Research Corporation\n");
826 fprintf(Parser_h
, " * with Purdue University Electrical Engineering\n");
827 fprintf(Parser_h
, " * with AHPCRC, University of Minnesota\n");
828 fprintf(Parser_h
, " * ANTLR Version %s\n", Version
);
829 fprintf(Parser_h
, " */\n\n");
831 if ( FirstAction
!= NULL
) dumpAction( FirstAction
, Parser_h
, 0, -1, 0, 1); /* MR11 MR15b */
833 fprintf(Parser_h
, "#ifndef %s_h\n", CurrentClassName
);
834 fprintf(Parser_h
, "#define %s_h\n\n", CurrentClassName
);
836 fprintf(Parser_h
, "#ifndef ANTLR_VERSION\n");
837 fprintf(Parser_h
, "#define ANTLR_VERSION %s\n",VersionDef
);
838 fprintf(Parser_h
, "#endif\n\n");
840 if ( GenAST
) fprintf(Parser_h
, "class ASTBase;\n");
842 fprintf(Parser_h
,"#ifndef zzTRACE_RULES\n"); /* MR20 */
843 fprintf(Parser_h
,"#define zzTRACE_RULES\n"); /* MR20 */
844 fprintf(Parser_h
,"#endif\n"); /* MR22 */
846 fprintf(Parser_h
, "#include \"%s\"\n\n", APARSER_H
);
848 if ( HdrAction
!= NULL
) dumpAction( HdrAction
, Parser_h
, 0, -1, 0, 1);
850 /* MR10 */ if (ClassDeclStuff
== NULL
) {
851 /* MR10 */ fprintf(Parser_h
, "class %s : public ANTLRParser {\n", CurrentClassName
);
853 /* MR10 */ fprintf(Parser_h
, "class %s %s {\n",CurrentClassName
,ClassDeclStuff
);
856 fprintf(Parser_h
, "public:\n"); /* MR1 */
857 fprintf(Parser_h
, "\tstatic const ANTLRChar *tokenName(int tk);\n");/* MR1 */
858 fprintf(Parser_h
, "\tenum { SET_SIZE = %i };\n",TokenNum
-1); /* MR21 */
859 fprintf(Parser_h
, "protected:\n");
860 fprintf(Parser_h
, "\tstatic const ANTLRChar *_token_tbl[];\n"); /* MR20 */
861 fprintf(Parser_h
, "private:\n");
864 /* Currently, this is only used in !GenCC mode */
875 fprintf(ErrFile
, "/*\n");
876 fprintf(ErrFile
, " * A n t l r S e t s / E r r o r F i l e H e a d e r\n");
877 fprintf(ErrFile
, " *\n");
878 fprintf(ErrFile
, " * Generated from:");
879 for (i
=0; i
<NumFiles
; i
++) fprintf(ErrFile
, " %s", FileStr
[i
]);
880 fprintf(ErrFile
, "\n");
881 fprintf(ErrFile
, " *\n");
882 fprintf(ErrFile
, " * Terence Parr, Russell Quong, Will Cohen, and Hank Dietz: 1989-2001\n");
883 fprintf(ErrFile
, " * Parr Research Corporation\n");
884 fprintf(ErrFile
, " * with Purdue University Electrical Engineering\n");
885 fprintf(ErrFile
, " * With AHPCRC, University of Minnesota\n");
886 fprintf(ErrFile
, " * ANTLR Version %s\n", Version
);
887 fprintf(ErrFile
, " */\n\n");
889 if ( FirstAction
!= NULL
) dumpAction( FirstAction
, ErrFile
, 0, -1, 0, 1); /* MR11 MR15b */
891 fprintf(ErrFile
, "#define ANTLR_VERSION %s\n", VersionDef
);
893 fprintf(ErrFile
, "#include \"pcctscfg.h\"\n");
894 fprintf(ErrFile
, "#include \"pccts_stdio.h\"\n");
895 if ( strcmp(ParserName
, DefaultParserName
)!=0 )
896 fprintf(ErrFile
, "#define %s %s\n", DefaultParserName
, ParserName
);
897 if ( strcmp(ParserName
, DefaultParserName
)!=0 )
898 fprintf(ErrFile
, "#include \"%s\"\n", RemapFileName
);
899 if ( HdrAction
!= NULL
) dumpAction( HdrAction
, ErrFile
, 0, -1, 0, 1 );
902 fprintf(ErrFile
, "#define ZZCAN_GUESS\n");
903 fprintf(ErrFile
, "#include \"pccts_setjmp.h\"\n");
906 fprintf(ErrFile
,"#ifndef zzTRACE_RULES\n"); /* MR20 */
907 fprintf(ErrFile
,"#define zzTRACE_RULES\n"); /* MR20 */
908 fprintf(ErrFile
,"#endif\n"); /* MR22 */
911 if ( OutputLL_k
> 1 ) fprintf(ErrFile
, "#define LL_K %d\n", OutputLL_k
);
913 if ( LexGen
) fprintf(ErrFile
, "#define zzEOF_TOKEN %d\n", (TokenInd
!=NULL
?TokenInd
[EofToken
]:EofToken
));
915 fprintf(ErrFile
, "#define zzSET_SIZE %d\n", NumWords(TokenNum
-1)*sizeof(unsigned));
916 if ( DemandLookahead
) fprintf(ErrFile
, "#define DEMAND_LOOK\n");
917 fprintf(ErrFile
, "#include \"antlr.h\"\n");
918 if ( GenAST
) fprintf(ErrFile
, "#include \"ast.h\"\n");
920 if ( UserDefdTokens
) fprintf(ErrFile
, "#include %s\n", UserTokenDefsFile
);
921 /* still need this one as it has the func prototypes */
922 fprintf(ErrFile
, "#include \"%s\"\n", DefFileName
);
923 fprintf(ErrFile
, "#include \"dlgdef.h\"\n");
924 fprintf(ErrFile
, "#include \"err.h\"\n\n");
926 /* Dump a zztokens for each automaton */
927 if ( strcmp(ParserName
, DefaultParserName
)!=0 )
929 fprintf(ErrFile
, "ANTLRChar *%s_zztokens[%d]={\n", ParserName
, TokenNum
-1);
933 fprintf(ErrFile
, "ANTLRChar *zztokens[%d]={\n", TokenNum
-1);
935 fprintf(ErrFile
, "\t/* 00 */\t\"Invalid\"");
936 for (i
=1; i
<TokenNum
-1; i
++)
939 if ( i
== EpToken
) continue;
940 /* remapped to invalid token? */
941 if ( TokenInd
!=NULL
&& TokenInd
[i
]>=LastTokenCounted
)
943 fprintf(ErrFile
, ",\n\t/* %02d */\t\"invalid\"", i
);
946 if ( TokenString(i
) != NULL
) {
947 te
=(TermEntry
*) hash_get(Tname
,TokenString(i
)); /* MR11 */
948 if (te
== NULL
|| te
->akaString
== NULL
) { /* MR11 */
949 fprintf(ErrFile
, ",\n\t/* %02d */\t\"%s\"", i
, TokenString(i
));
951 fprintf(ErrFile
, ",\n\t/* %02d */\t\"%s\"", i
, te
->akaString
); /* MR11 */
956 /* look in all lexclasses for the reg expr */
957 for (j
=0; j
<NumLexClasses
; j
++)
960 if ( ExprString(i
) != NULL
)
962 fprintf(ErrFile
, ",\n\t/* %02d */\t", i
);
963 dumpExpr(ErrFile
, ExprString(i
));
967 if ( j
>=NumLexClasses
)
969 if ( UserDefdTokens
)
971 fprintf(ErrFile
, ",\n\t/* %02d */\t\"\"", i
);
974 fatal_internal(eMsgd("No label or expr for token %d",i
));
978 fprintf(ErrFile
, "\n};\n");
983 dumpExpr( FILE *f
, char *e
)
992 if ( *e
=='\\' && *(e
+1)=='\\' )
993 {putc('\\', f
); putc('\\', f
); e
+=2;}
994 else if ( *e
=='\\' && *(e
+1)=='"' )
995 {putc('\\', f
); putc('"', f
); e
+=2;}
996 else if ( *e
=='\\' ) {putc('\\', f
); putc('\\', f
); e
++;}
997 else {putc(*e
, f
); e
++;}
1003 isTermEntryTokClass(TermEntry
*te
)
1005 isTermEntryTokClass(te
)
1014 if (tclasses
== NULL
) return 0;
1016 for (t
= tclasses
->next
; t
!=NULL
; t
=t
->next
)
1018 p
= (TCnode
*) t
->elem
;
1019 tokstr
= TokenString(p
->tok
);
1020 lexmode(p
->lexclass
); /* switch to lexclass where tokclass is defined */
1021 q
= (TermEntry
*) hash_get(Tname
, tokstr
);
1022 if (q
== te
) return 1;