2
* globals.c -- File containing all variables/tables visible to all files.
6
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
7
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
8
* company may do whatever they wish with source code distributed with
9
* PCCTS or the code generated by PCCTS, including the incorporation of
10
* PCCTS, or its output, into commerical software.
12
* We encourage users to develop software with PCCTS. However, we do ask
13
* that credit is given to us for developing PCCTS. By "credit",
14
* we mean that if you incorporate our source code into one of your
15
* programs (commercial product, research project, or otherwise) that you
16
* acknowledge this fact somewhere in the documentation, research report,
17
* etc... If you like PCCTS and have developed a nice tool with the
18
* output, please mention that you developed it using PCCTS. In
19
* addition, we ask that this header remain intact in our source code.
20
* As long as these guidelines are kept, we expect to continue enhancing
21
* this system and expect to make other tools available as they are
26
* Parr Research Corporation
27
* with Purdue University and AHPCRC, University of Minnesota
40
char Version[] = "1.33MR20" ; /* PCCTS version number */ /* MRXXX */
41
char VersionDef[] = "13320"; /* same (except int equiv for preproc symbol) */ /* MRXXX */
43
char LexStartSymbol[] = "START";/* Name of starting lexical class/automaton */
44
char *RemapFileName = "remap.h";
45
char *DlgFileName = "parser.dlg";
46
char *DefFileName = "tokens.h";
47
char *ErrFileName = "err.c";
48
char *ModeFileName = "mode.h";
49
char *StdMsgName = NULL;
51
char *ParserName = DefaultParserName;
53
/* list of PCCTS supplied support symbols; these are renamed when more than
54
* one ANTLR-generated parsers are linked together to avoid name conflicts.
55
* Can't use '##' ANSIC preprocessor concat operator with K&R and:
56
* #define zzskip zzparser ## skip
57
* will not work for ANSI/C++ as 'zzparserskip' is created w/o zzparser
58
* being substituted--ack!!!
60
char *StandardSymbols[] = {
68
"inf_text_buffer_ptr",
69
"inf_text_buffer_size",
91
"zzrestore_antlr_state",
100
"zzconsumeUntilToken",
104
"_zzsetmatch_wdfltsig",
124
"zzrestore_dlg_state",
137
"zztokens", /* list of token regular expressions */
141
"zzTraceOptionValue", /* MR10 */
142
"zzTraceGuessOptionValue", /* MR10 */
143
"zzTraceCurrentRuleName", /* MR10 */
144
"zzTraceDepth", /* MR10 */
145
"zzGuessSeq", /* MR10 */
146
"zzSyntaxErrCount", /* MR11 */
147
"zzLexErrCount", /* MR11 */
148
"zzTraceGuessDone", /* MR13 - BJS */
149
"zzTraceGuessFail", /* MR13 - BJS */
150
"zzTraceGuessOption", /* MR13 - BJS */
151
"zzTraceIn", /* MR13 - BJS */
152
"zzTraceOption", /* MR13 - BJS */
153
"zzTraceOut", /* MR13 - BJS */
154
"zzTraceReset", /* MR13 - BJS */
155
NULL /* must be present */
158
/* list of PCCTS supplied support functions; these are renamed when more than
159
* one ANTLR-generated parsers are linked together to avoid name conflicts.
161
char *ASTSymbols[] = {
175
NULL /* must be present */
178
/* Current ambiguity examination information */
179
int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
183
/* M e t h o d T a b l e s */
185
* The following tables are used to fill syntax diagram nodes with the correct
186
* function pointers for computing FIRST sets and printing themselves.
189
/* fpTraverse[node type] == pointer to function that calculates trees
190
* representing the FIRST sets for that node (maintains spatial info).
191
* We use 'struct _tree' not 'tree' due to a g++ 2.4.3 bug.
194
struct _tree *(*fpTraverse[NumNodeTypes+1])(... /* Node *, int, set * */) = {
196
(struct _tree *(*)(...)) tJunc,
197
(struct _tree *(*)(...)) tRuleRef,
198
(struct _tree *(*)(...)) tToken,
199
(struct _tree *(*)(...)) tAction
202
Tree *(*fpTraverse[NumNodeTypes+1])() = {
211
/* fpReach[node type] == pointer to function that calculates FIRST set for
212
* that node. (r stands for reach). We use 'struct _set' not 'set'
213
* due to a g++ 2.4.3 bug.
216
struct _set (*fpReach[NumNodeTypes+1])(... /* Node *, int, set * */) = {
218
(struct _set (*)(...)) rJunc,
219
(struct _set (*)(...)) rRuleRef,
220
(struct _set (*)(...)) rToken,
221
(struct _set (*)(...)) rAction
224
set (*fpReach[NumNodeTypes+1])() = {
233
/* fpPrint[node type] == pointer to function that knows how to print that node. */
235
void (*fpPrint[NumNodeTypes+1])(... /* Node * */) = {
237
(void (*)(...)) pJunc,
238
(void (*)(...)) pRuleRef,
239
(void (*)(...)) pToken,
240
(void (*)(...)) pAction
243
void (*fpPrint[NumNodeTypes+1])() = {
252
char *decodeJType[] = {
266
/* H a s h T a b l e s */
268
Entry **Tname, /* Table of all token names (maps name to tok num)*/
269
**Texpr, /* Table of all token expressions
270
(maps expr to tok num) */
271
**Rname, /* Table of all Rules (has ptr to start of rule) */
272
**Fcache, /* Cache of First/Follow Computations */
273
**Tcache; /* Tree cache; First/Follow for permute trees */
274
Entry **Elabel; /* Table of all element label names */
275
Entry **Sname; /* Signal names */
276
Entry **Pname; /* symbolic predicate names MR11 */
279
/* V a r i a b l e s */
281
int Save_argc; /* MR10 */
282
char **Save_argv; /* MR10 */
283
int EpToken=0; /* Imaginary Epsilon token number */
285
int CurFile= -1; /* Index into FileStr table */
286
char *CurPredName=NULL; /* MR11 */
287
char *CurRule=NULL; /* Pointer to current rule name */
288
int CurRuleDebug=0; /* MR13 debug flag */
289
RuleEntry *CurRuleNode=NULL;/* Pointer to current rule node in syntax tree */
290
char *CurRetDef=NULL; /* Pointer to current return type definition */
291
char *CurParmDef=NULL; /* Pointer to current parameter definition */
292
Junction *CurRuleBlk=NULL; /* Pointer to current block node for enclosing block */
293
ListNode *CurExGroups=NULL; /* Current list of exception groups for rule/alts */
294
ListNode *CurElementLabels=NULL;
296
/* MR10 used by <<>>? to set "label_used_in_semantic_pred" */
297
/* MR10 this will force LT(i) assignment even in guess mode */
299
ListNode *CurActionLabels=NULL; /* MR10 Element Labels appearing in last action */
300
int numericActionLabel=0 ; /* MR10 << ... $1 ... >> or << ... $1 ... >>? */
301
ListNode *NumericPredLabels=NULL; /* MR10 << ... $1 ... >>? ONLY */
302
ListNode *ContextGuardPredicateList=NULL; /* MR13 for re-evaluating predicates
303
after meta tokens are defined */
305
int CurBlockID=0; /* Unique int for each block */
307
Junction *CurAltStart = NULL; /* Junction node that starts the alt */
308
Junction *OuterAltStart = NULL; /* For chaining exception groups MR7 */
309
int NumRules=0; /* Rules are from 1 to n */
310
FILE *output=NULL; /* current parser output file */
311
FILE *input=NULL; /* current grammar input file */
312
char *FileStr[MaxNumFiles];/* Ptr to array of file names on command-line */
313
int NumFiles=0; /* current grammar file number */
315
void (**fpTrans)(...), /* array of ptrs to funcs that translate nodes */
316
(**fpJTrans)(...); /* ... that translate junctions */
318
void (**fpTrans)(), /* array of ptrs to funcs that translate nodes */
319
(**fpJTrans)(); /* ... that translate junctions */
321
int **FoStack; /* Array of LL_k ptrs to stacks of rule numbers */
322
int **FoTOS; /* FOLLOW stack top-of-stack pointers */
323
Junction *SynDiag = NULL; /* Pointer to start of syntax diagram */
324
int BlkLevel=1; /* Current block level. Set by antlr.g, used by
325
* scanner to translate $i.j attributes */
326
set reserved_positions; /* set of token positions reserved by '#token T=i' cmds */
327
set all_tokens; /* set of all token types */
328
set imag_tokens; /* set of all imaginary token types (EpToken, errclasses...) */
329
set tokclasses; /* set of all token class token types */
330
ListNode *ForcedTokens = 0; /* list of token_id/token_num pairs to remap */
331
ListNode *MetaTokenNodes=NULL; /* list of meta token refs such as token classes etc... */
332
int *TokenInd=NULL; /* an indirection level between token num and position
333
* of that token def in TokenStr and ExprStr */
334
int LastTokenCounted=0; /* ==TokenNum if no token renumbering (same as old TokenNum) */
335
int TokenNum=TokenStart;
336
char **TokenStr=NULL; /* map token # to token name */
337
char **ExprStr=NULL; /* map token # to expr */
338
Junction **RulePtr=NULL; /* map rule # to RuleBlk node of rule */
339
ListNode *ExprOrder=NULL; /* list of exprs as they are found in grammar */
340
ListNode *BeforeActions=NULL;/* list of grammar actions before rules */
341
ListNode *AfterActions=NULL;/* list of grammar actions after rules */
342
ListNode *LexActions=NULL; /* list of lexical actions */
345
/* MR1 11-Apr-97 Provide mechanism for inserting code into DLG class */
346
/* MR1 via #lexmember <<....>> */
347
/* MR1 via #lexprefix <<....>> */
350
ListNode *LexMemberActions=NULL;/* list of lexical header member decl MR1 */
351
ListNode *LexPrefixActions=NULL;/* list of lexical header #include decl MR1 */
352
ListNode **Cycles=NULL; /* list of cycles (for each k) found when
354
ListNode *eclasses=NULL; /* list of error classes */
355
ListNode *tclasses=NULL; /* list of token classes */
356
LClass lclass[MaxLexClasses]; /* array of lex class definitions */
357
int CurrentLexClass; /* index into lclass */
358
int NumLexClasses=0; /* in range 1..MaxLexClasses (init 0) */
360
char *HdrAction=NULL; /* action defined with #header */
361
char *FirstAction=NULL; /* action defined with #first MR11 */
362
FILE *ErrFile; /* sets and error recovery stuff */
363
FILE *DefFile=NULL; /* list of tokens, return value structs, setwd defs */
364
FILE *MRinfoFile=NULL; /* MR10 information file */
365
int MRinfo=0; /* MR10 */
366
int MRinfoSeq=0; /* MR10 */
367
int InfoP=0; /* MR10 predicates */
368
int InfoT=0; /* MR10 tnodes */
369
int InfoF=0; /* MR10 first/follow sets */
370
int InfoM=0; /* MR10 monitor progress */
371
int InfoO=0; /* MR12 orphan rules */
372
int TnodesInUse=0; /* MR10 */
373
int TnodesPeak=0; /* MR10 */
374
int TnodesAllocated=0; /* MR10 */
375
int TnodesReportThreshold=0; /* MR11 */
376
int PotentialSuppression=0; /* MR10 */
377
int PotentialDummy=0; /* MR10 */
378
int CannotContinue=FALSE;
379
int OutputLL_k = 1; /* LL_k for parsing must be power of 2 */
380
int action_file; /* used to track start of action */
382
int FoundGuessBlk=0; /* there is a (...)? block somewhere in grammar */
383
int FoundException=0; /* there is an exception somewhere in grammar */
384
/* MR6 Distinguish between @ operator and real exception */
385
/* MR6 by keeping separate flags for @ operator and real exceptions */
386
int FoundAtOperator=0; /* MR6 */
387
int FoundExceptionGroup=0; /* MR6 */
388
int pLevel=0; /* print Level */
389
int pAlt1,pAlt2; /* print "==>" in front of these alts */
391
/* C++ output stuff */
392
FILE *Parser_h, /* where subclass of ANTLRParser goes */
393
*Parser_c; /* where code for subclass of ANTLRParser goes */
394
char Parser_h_Name[MaxFileName+1] = "";
395
char Parser_c_Name[MaxFileName+1] = "";
396
char MRinfoFile_Name[MaxFileName+1] = ""; /* MR10 */
397
char *ClassDeclStuff=NULL; /* MR10 */
398
/* list of actions inside the #class {...} defs */
399
ListNode *class_before_actions=NULL;
400
ListNode *class_after_actions=NULL;
402
char CurrentClassName[MaxRuleName]="";
403
int no_classes_found=1;
404
char *UserTokenDefsFile;
405
int UserDefdTokens=0; /* found #tokdefs? */
406
char *OutputDirectory=TopDirectory;
407
ExceptionGroup *DefaultExGroup = NULL;
408
int NumSignals = NumPredefinedSignals;
409
int ContextGuardTRAV=0;
411
char *MR_AmbAidRule=NULL; /* MR11 */
412
int MR_AmbAidLine=0; /* MR11 */
413
int MR_AmbAidDepth=0; /* MR11 */
414
int MR_AmbAidMultiple=0; /* MR11 */
415
int MR_skipped_e3_report=0; /* MR11 */
416
int MR_usingPredNames=0; /* MR11 */
417
int MR_BadExprSets=0; /* MR13 */
418
int MR_Inhibit_Tokens_h_Gen=0; /* MR13 */
419
int NewAST=0; /* MR13 */
420
int AlphaBetaTrace=0; /* MR14 */
421
int MR_AlphaBetaMessageCount=0; /* MR14 */
422
int MR_AlphaBetaWarning=0; /* MR14 */
423
int MR_ErrorSetComputationActive=0; /* MR14 */
424
int MR_MaintainBackTrace=0; /* MR14 */
425
set MR_CompromisedRules; /* MR14 */
427
Junction *MR_RuleBlkWithHalt; /* MR10 */
429
/* C m d - L i n e O p t i o n s */
431
int LL_k=1; /* how many tokens of full lookahead */
432
int CLL_k= -1; /* how many tokens of compressed lookahead */
433
int PrintOut = FALSE; /* print out the grammar */
434
int PrintAnnotate = FALSE;/* annotate printout with FIRST sets */
435
int CodeGen=TRUE; /* Generate output code? */
436
int LexGen=TRUE; /* Generate lexical files? (tokens.h, parser.dlg) */
437
int GenAST=FALSE; /* Generate AST's? */
438
int GenANSI=FALSE; /* Generate ANSI code where necessary */
439
int GenExprSetsOpt=TRUE;/* use sets not (LA(1)==tok) expression lists */
440
int GenCR=FALSE; /* Generate cross reference? */
441
int GenLineInfo=FALSE; /* Generate # line "file" stuff? */
442
int GenLineInfoMS=FALSE;/* Like -gl but replace "\" with "/" for MS C/C++ systems */
443
int TraceGen=FALSE; /* Generate code to trace rule invocation */
444
int elevel=1; /* error level for ambiguity messages */
445
int GenEClasseForRules=0;/* don't generate eclass for each rule */
446
int TreeResourceLimit= -1;/* don't limit tree resource */
447
int DemandLookahead = 0;/* demand/delayed lookahead or not */
448
char *RulePrefix = ""; /* prefix each generated rule with this */
449
char *stdpccts = "stdpccts.h";/* where to generate std pccts include file */
450
int GenStdPccts = 0; /* don't gen stdpccts.h? */
451
int ParseWithPredicates = 1;
452
int WarningLevel = 1;
453
int UseStdout = 0; /* MR6 */
454
int TabWidth = 0; /* MR6 */
455
int HoistPredicateContext = 0;
456
int MRhoisting = 0; /* MR9 */
457
int MRhoistingk = 0; /* MR13 */
458
int MR_debugGenRule=0; /* MR11 */
460
int GenCC = 0; /* Generate C++ output */
462
PointerStack MR_BackTraceStack={0,0,NULL}; /* MR10 */
463
PointerStack MR_PredRuleRefStack={0,0,NULL}; /* MR10 */
464
PointerStack MR_RuleBlkWithHaltStack={0,0,NULL}; /* MR10 */
466
/* DontCopyTokens and Pragma_DupLabeledTokens were a bad idea. I've just
467
turned them off rather than backpatching the code. Who knows? We
468
may need them in the future.
470
int DontCopyTokens = 1; /* in C++, don't copy ANTLRToken passed to ANTLR */