2 * globals.c -- File containing all variables/tables visible to all files.
4 * $Id: globals.c,v 1.5 95/10/05 11:57:02 parrt Exp $
9 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
10 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
11 * company may do whatever they wish with source code distributed with
12 * PCCTS or the code generated by PCCTS, including the incorporation of
13 * PCCTS, or its output, into commerical software.
15 * We encourage users to develop software with PCCTS. However, we do ask
16 * that credit is given to us for developing PCCTS. By "credit",
17 * we mean that if you incorporate our source code into one of your
18 * programs (commercial product, research project, or otherwise) that you
19 * acknowledge this fact somewhere in the documentation, research report,
20 * etc... If you like PCCTS and have developed a nice tool with the
21 * output, please mention that you developed it using PCCTS. In
22 * addition, we ask that this header remain intact in our source code.
23 * As long as these guidelines are kept, we expect to continue enhancing
24 * this system and expect to make other tools available as they are
29 * Parr Research Corporation
30 * with Purdue University and AHPCRC, University of Minnesota
44 char Version[] = "1.33" ; /* PCCTS version number */
45 char VersionDef[] = "133"; /* same (except int equiv for preproc symbol) */
46 char LexStartSymbol[] = "START";/* Name of starting lexical class/automaton */
48 char *RemapFileName = "remap.h";
49 char *DlgFileName = "parser.dlg";
50 char *DefFileName = "tokens.h";
51 char *ErrFileName = "err.c";
52 char *ModeFileName = "mode.h";
54 char *ParserName = DefaultParserName;
56 /* list of PCCTS supplied support symbols; these are renamed when more than
57 * one ANTLR-generated parsers are linked together to avoid name conflicts.
58 * Can't use '##' ANSIC preprocessor concat operator with K&R and:
59 * #define zzskip zzparser ## skip
60 * will not work for ANSI/C++ as 'zzparserskip' is created w/o zzparser
61 * being substituted--ack!!!
63 char *StandardSymbols[] = {
71 "inf_text_buffer_ptr",
72 "inf_text_buffer_size",
94 "zzrestore_antlr_state",
103 "zzconsumeUntilToken",
107 "_zzsetmatch_wdfltsig",
127 "zzrestore_dlg_state",
140 "zztokens", /* list of token regular expressions */
144 NULL /* must be present */
147 /* list of PCCTS supplied support functions; these are renamed when more than
148 * one ANTLR-generated parsers are linked together to avoid name conflicts.
150 char *ASTSymbols[] = {
164 NULL /* must be present */
167 /* Current ambiguity examination information */
168 int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
172 /* M e t h o d T a b l e s */
174 * The following tables are used to fill syntax diagram nodes with the correct
175 * function pointers for computing FIRST sets and printing themselves.
178 /* fpTraverse[node type] == pointer to function that calculates trees
179 * representing the FIRST sets for that node (maintains spatial info).
180 * We use 'struct _tree' not 'tree' due to a g++ 2.4.3 bug.
183 struct _tree *(*fpTraverse[NumNodeTypes+1])(... /* Node *, int, set * */) = {
185 (struct _tree *(*)(...)) tJunc,
186 (struct _tree *(*)(...)) tRuleRef,
187 (struct _tree *(*)(...)) tToken,
188 (struct _tree *(*)(...)) tAction
191 Tree *(*fpTraverse[NumNodeTypes+1])() = {
200 /* fpReach[node type] == pointer to function that calculates FIRST set for
201 * that node. (r stands for reach). We use 'struct _set' not 'set'
202 * due to a g++ 2.4.3 bug.
205 struct _set (*fpReach[NumNodeTypes+1])(... /* Node *, int, set * */) = {
207 (struct _set (*)(...)) rJunc,
208 (struct _set (*)(...)) rRuleRef,
209 (struct _set (*)(...)) rToken,
210 (struct _set (*)(...)) rAction
213 set (*fpReach[NumNodeTypes+1])() = {
222 /* fpPrint[node type] == pointer to function that knows how to print that node. */
224 void (*fpPrint[NumNodeTypes+1])(... /* Node * */) = {
226 (void (*)(...)) pJunc,
227 (void (*)(...)) pRuleRef,
228 (void (*)(...)) pToken,
229 (void (*)(...)) pAction
232 void (*fpPrint[NumNodeTypes+1])() = {
241 char *decodeJType[] = {
255 /* H a s h T a b l e s */
257 Entry **Tname, /* Table of all token names (maps name to tok num)*/
258 **Texpr, /* Table of all token expressions
259 (maps expr to tok num) */
260 **Rname, /* Table of all Rules (has ptr to start of rule) */
261 **Fcache, /* Cache of First/Follow Computations */
262 **Tcache; /* Tree cache; First/Follow for permute trees */
263 Entry **Elabel; /* Table of all element label names */
264 Entry **Sname; /* Signal names */
267 /* V a r i a b l e s */
269 int EpToken=0; /* Imaginary Epsilon token number */
271 int CurFile= -1; /* Index into FileStr table */
272 char *CurRule=NULL; /* Pointer to current rule name */
273 RuleEntry *CurRuleNode=NULL;/* Pointer to current rule node in syntax tree */
274 char *CurRetDef=NULL; /* Pointer to current return type definition */
275 char *CurParmDef=NULL; /* Pointer to current parameter definition */
276 Junction *CurRuleBlk=NULL; /* Pointer to current block node for enclosing block */
277 ListNode *CurExGroups=NULL; /* Current list of exception groups for rule/alts */
278 ListNode *CurElementLabels=NULL;
279 int CurBlockID=0; /* Unique int for each block */
281 Junction *CurAltStart = NULL; /* Junction node that starts the alt */
282 int NumRules=0; /* Rules are from 1 to n */
283 FILE *output=NULL; /* current parser output file */
284 FILE *input=NULL; /* current grammar input file */
285 char *FileStr[MaxNumFiles];/* Ptr to array of file names on command-line */
286 int NumFiles=0; /* current grammar file number */
288 void (**fpTrans)(...), /* array of ptrs to funcs that translate nodes */
289 (**fpJTrans)(...); /* ... that translate junctions */
291 void (**fpTrans)(), /* array of ptrs to funcs that translate nodes */
292 (**fpJTrans)(); /* ... that translate junctions */
294 int **FoStack; /* Array of LL_k ptrs to stacks of rule numbers */
295 int **FoTOS; /* FOLLOW stack top-of-stack pointers */
296 Junction *SynDiag = NULL; /* Pointer to start of syntax diagram */
297 int BlkLevel=1; /* Current block level. Set by antlr.g, used by
298 * scanner to translate $i.j attributes */
299 set reserved_positions; /* set of token positions reserved by '#token T=i' cmds */
300 set all_tokens; /* set of all token types */
301 set imag_tokens; /* set of all imaginary token types (EpToken, errclasses...) */
302 set tokclasses; /* set of all token class token types */
303 ListNode *ForcedTokens = 0; /* list of token_id/token_num pairs to remap */
304 ListNode *MetaTokenNodes=NULL; /* list of meta token refs such as token classes etc... */
305 int *TokenInd=NULL; /* an indirection level between token num and position
306 * of that token def in TokenStr and ExprStr */
307 int LastTokenCounted=0; /* ==TokenNum if no token renumbering (same as old TokenNum) */
308 int TokenNum=TokenStart;
309 char **TokenStr=NULL; /* map token # to token name */
310 char **ExprStr=NULL; /* map token # to expr */
311 Junction **RulePtr=NULL; /* map rule # to RuleBlk node of rule */
312 ListNode *ExprOrder=NULL; /* list of exprs as they are found in grammar */
313 ListNode *BeforeActions=NULL;/* list of grammar actions before rules */
314 ListNode *AfterActions=NULL;/* list of grammar actions after rules */
315 ListNode *LexActions=NULL; /* list of lexical actions */
316 ListNode **Cycles=NULL; /* list of cycles (for each k) found when
318 ListNode *eclasses=NULL; /* list of error classes */
319 ListNode *tclasses=NULL; /* list of token classes */
320 LClass lclass[MaxLexClasses]; /* array of lex class definitions */
321 int CurrentLexClass; /* index into lclass */
322 int NumLexClasses=0; /* in range 1..MaxLexClasses (init 0) */
324 char *HdrAction=NULL; /* action defined with #header */
325 FILE *ErrFile; /* sets and error recovery stuff */
326 FILE *DefFile=NULL; /* list of tokens, return value structs, setwd defs */
327 int CannotContinue=FALSE;
328 int OutputLL_k = 1; /* LL_k for parsing must be power of 2 */
329 int action_file; /* used to track start of action */
331 int FoundGuessBlk=0; /* there is a (...)? block somewhere in grammar */
332 int FoundException=0; /* there is an exception somewhere in grammar */
333 int pLevel=0; /* print Level */
334 int pAlt1,pAlt2; /* print "==>" in front of these alts */
336 /* C++ output stuff */
337 FILE *Parser_h, /* where subclass of ANTLRParser goes */
338 *Parser_c; /* where code for subclass of ANTLRParser goes */
339 char Parser_h_Name[MaxFileName+1] = "";
340 char Parser_c_Name[MaxFileName+1] = "";
342 /* list of actions inside the #class {...} defs */
343 ListNode *class_before_actions=NULL;
344 ListNode *class_after_actions=NULL;
346 char CurrentClassName[MaxRuleName]="";
347 int no_classes_found=1;
348 char *UserTokenDefsFile;
349 int UserDefdTokens=0; /* found #tokdefs? */
350 char *OutputDirectory=TopDirectory;
351 ExceptionGroup *DefaultExGroup = NULL;
352 int NumSignals = NumPredefinedSignals;
353 int ContextGuardTRAV=0;
356 /* C m d - L i n e O p t i o n s */
358 int LL_k=1; /* how many tokens of full lookahead */
359 int CLL_k= -1; /* how many tokens of compressed lookahead */
360 int PrintOut = FALSE; /* print out the grammar */
361 int PrintAnnotate = FALSE;/* annotate printout with FIRST sets */
362 int CodeGen=TRUE; /* Generate output code? */
363 int LexGen=TRUE; /* Generate lexical files? (tokens.h, parser.dlg) */
364 int GenAST=FALSE; /* Generate AST's? */
365 int GenANSI=FALSE; /* Generate ANSI code where necessary */
366 int GenExprSets=TRUE; /* use sets not (LA(1)==tok) expression lists */
367 int GenCR=FALSE; /* Generate cross reference? */
368 int GenLineInfo=FALSE; /* Generate # line "file" stuff? */
369 int TraceGen=FALSE; /* Generate code to trace rule invocation */
370 int elevel=1; /* error level for ambiguity messages */
371 int GenEClasseForRules=0;/* don't generate eclass for each rule */
372 int TreeResourceLimit= -1;/* don't limit tree resource */
373 int DemandLookahead = 0;/* demand/delayed lookahead or not */
374 char *RulePrefix = ""; /* prefix each generated rule with this */
375 char *stdpccts = "stdpccts.h";/* where to generate std pccts include file */
376 int GenStdPccts = 0; /* don't gen stdpccts.h? */
377 int ParseWithPredicates = 1;
378 int WarningLevel = 1;
379 int HoistPredicateContext = 0;
380 int GenCC = 0; /* Generate C++ output */
382 /* DontCopyTokens and Pragma_DupLabeledTokens were a bad idea. I've just
383 turned them off rather than backpatching the code. Who knows? We
384 may need them in the future.
386 int DontCopyTokens = 1; /* in C++, don't copy ANTLRToken passed to ANTLR */