+++ /dev/null
-/*\r
- * main.c -- main program for PCCTS ANTLR.\r
- *\r
- * SOFTWARE RIGHTS\r
- *\r
- * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
- * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
- * company may do whatever they wish with source code distributed with\r
- * PCCTS or the code generated by PCCTS, including the incorporation of\r
- * PCCTS, or its output, into commerical software.\r
- *\r
- * We encourage users to develop software with PCCTS. However, we do ask\r
- * that credit is given to us for developing PCCTS. By "credit",\r
- * we mean that if you incorporate our source code into one of your\r
- * programs (commercial product, research project, or otherwise) that you\r
- * acknowledge this fact somewhere in the documentation, research report,\r
- * etc... If you like PCCTS and have developed a nice tool with the\r
- * output, please mention that you developed it using PCCTS. In\r
- * addition, we ask that this header remain intact in our source code.\r
- * As long as these guidelines are kept, we expect to continue enhancing\r
- * this system and expect to make other tools available as they are\r
- * completed.\r
- *\r
- * ANTLR 1.33\r
- * Terence Parr\r
- * Parr Research Corporation\r
- * with Purdue University and AHPCRC, University of Minnesota\r
- * 1989-2001\r
- */\r
-\r
-/* To set a breakpoint just before exit look for "cleanUp". */\r
-/* To set a breakpoint for fatal error look for "fatal_intern" */\r
-\r
-#include <stdio.h>\r
-\r
-#include "pcctscfg.h"\r
-#include "stdpccts.h"\r
-\r
-#define MAX_INT_STACK 50\r
-static int istack[MAX_INT_STACK]; /* Int stack */\r
-static int isp = MAX_INT_STACK;\r
-\r
-static int DontAcceptFiles = 0; /* if stdin, don't read files */\r
-static int DontAcceptStdin = 0; /* if files seen first, don't accept stdin */\r
-\r
-static int tnodes_used_in_guard_predicates_etc; /* MR10 */\r
-\r
- /* C m d - L i n e O p t i o n S t r u c t & F u n c s */\r
-\r
-typedef struct _Opt {\r
- char *option;\r
- int arg;\r
-#ifdef __cplusplus\r
- void (*process)(...);\r
-#else\r
- void (*process)();\r
-#endif\r
- char *descr;\r
- } Opt;\r
-\r
-#ifdef __USE_PROTOS\r
-extern void ProcessArgs(int, char **, Opt *);\r
-#else\r
-extern void ProcessArgs();\r
-#endif\r
-\r
-#ifdef __USE_PROTOS\r
-int ci_strequ(char *a,char *b)\r
-#else\r
-int ci_strequ(a,b)\r
- char *a;\r
- char *b;\r
-#endif\r
-{\r
- for ( ;*a != 0 && *b != 0; a++, b++) {\r
- if (toupper(*a) != toupper(*b)) return 0;\r
- }\r
- return (*a == *b);\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pStdin( void )\r
-#else\r
-pStdin( )\r
-#endif\r
-{\r
- if ( DontAcceptStdin )\r
- {\r
- warnNoFL("'-' (stdin) ignored as files were specified first");\r
- return;\r
- }\r
-\r
- require(NumFiles<MaxNumFiles,"exceeded max # of input files");\r
- FileStr[NumFiles++] = "stdin";\r
- DontAcceptFiles = 1;\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pFile( char *s )\r
-#else\r
-pFile( s )\r
-char *s;\r
-#endif\r
-{\r
- if ( *s=='-' ) { warnNoFL( eMsg1("invalid option: '%s'",s) ); return; }\r
- if ( DontAcceptFiles )\r
- {\r
- warnNoFL(eMsg1("file '%s' ignored as '-' (stdin option) was specified first",s));\r
- return;\r
- }\r
-\r
- require(NumFiles<MaxNumFiles,"exceeded max # of input files");\r
- FileStr[NumFiles++] = s;\r
- DontAcceptStdin = 1;\r
-}\r
-\r
-/* MR14\r
- Allow input to be a file containing a list of files\r
- Bernard Giroud (b_giroud@decus.ch)\r
-*/\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pFileList( char *s, char *t )\r
-#else\r
-pFileList( s, t )\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
-#define MaxFLArea 1024\r
- FILE *fl;\r
- static char Fn_in_Fl[MaxFLArea] = "";\r
- char one_fn[MaxFileName];\r
- char *flp = &Fn_in_Fl[0];\r
- int fnl, left = MaxFLArea, i;\r
-\r
- if ( *t=='-' ) { warnNoFL( eMsg1("invalid option: '%s'",t) ); return; }\r
- if ( DontAcceptFiles )\r
- {\r
- warnNoFL(eMsg1("file '%s' ignored as '-' (stdin option) was specified first",t));\r
- return;\r
- }\r
-\r
- if ((fl = fopen(t, "r")) == NULL)\r
- {\r
- warnNoFL(eMsg1("file '%s' can't be opened", t));\r
- return;\r
- }\r
- for (;;)\r
- {\r
- if (fgets(one_fn, 128 - 1, fl) == NULL)\r
- break;\r
- fnl = strlen(one_fn);\r
- require(fnl<=left, "no more room in File List Area");\r
- /* drop the trailing LF */\r
- if (one_fn[fnl - 1] == 0x0a) one_fn[fnl - 1] = ' ';\r
- strcat(Fn_in_Fl, one_fn);\r
- left = left - fnl;\r
- require(NumFiles<MaxNumFiles,"exceeded max # of input files");\r
- FileStr[NumFiles++] = flp;\r
- flp = flp + fnl;\r
- }\r
- fclose(fl);\r
- for (i=0;i < MaxFLArea;i++) if (Fn_in_Fl[i] == ' ') Fn_in_Fl[i] = '\0';\r
- DontAcceptStdin = 1;\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pLLK( char *s, char *t )\r
-#else\r
-pLLK( s, t )\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- LL_k = atoi(t);\r
- if ( LL_k <= 0 ) {\r
- warnNoFL("must have at least one token of lookahead (setting to 1)");\r
- LL_k = 1;\r
- }\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pCk( char *s, char *t )\r
-#else\r
-pCk( s, t )\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- CLL_k = atoi(t);\r
- if ( CLL_k <= 0 ) {\r
- warnNoFL("must have at least one token of look-ahead (setting to 1)");\r
- CLL_k = 1;\r
- }\r
-}\r
-\r
-static void /* MR6 */\r
-#ifdef __USE_PROTOS\r
-pTab( char *s, char *t ) /* MR6 */\r
-#else\r
-pTab( s, t ) /* MR6 */\r
-char *s; /* MR6 */\r
-char *t; /* MR6 */\r
-#endif\r
-{ /* MR6 */\r
- TabWidth = atoi(t); /* MR6 */\r
- if ( TabWidth < 0 || TabWidth > 8 ) { /* MR6 */\r
- warnNoFL("tab width must be between 1 and 8"); /* MR6 */\r
- TabWidth=0; /* MR6 */\r
- } /* MR6 */\r
-} /* MR6 */\r
-\r
-static int ambAidDepthSpecified=0; /* MR11 */\r
-\r
-static void /* MR11 */\r
-#ifdef __USE_PROTOS\r
-pAAd( char *s, char *t ) /* MR11 */\r
-#else\r
-pAAd( s, t ) /* MR11 */\r
-char *s; /* MR11 */\r
-char *t; /* MR11 */\r
-#endif\r
-{ /* MR11 */\r
- ambAidDepthSpecified=1; /* MR11 */\r
- MR_AmbAidDepth = atoi(t); /* MR11 */\r
-} /* MR11 */\r
-\r
-static void /* MR11 */\r
-#ifdef __USE_PROTOS\r
-pTreport( char *s, char *t ) /* MR11 */\r
-#else\r
-pTreport( s, t ) /* MR11 */\r
- char *s; /* MR11 */\r
- char *t; /* MR11 */\r
-#endif\r
-{ /* MR11 */\r
- TnodesReportThreshold = atoi(t); /* MR11 */\r
-} /* MR11 */\r
-\r
-#ifdef __USE_PROTOS\r
-void chkGTFlag(void) /* 7-Apr-97 MR1 */\r
-#else\r
-void chkGTFlag() /* 7-Apr-97 MR1 */\r
-#endif\r
-{\r
- if ( !GenAST )\r
- warn("#-variable or other AST item referenced w/o -gt option");\r
-}\r
-\r
-\r
-#ifdef __USE_PROTOS\r
-static void pInfo(char *s, char *t) /* MR10 */\r
-#else\r
-static void pInfo(s,t) /* MR10 */\r
- char *s;\r
- char *t;\r
-#endif\r
-{\r
- char *p;\r
- int q;\r
- for (p=t; *p != 0; p++) {\r
- q=tolower(*p);\r
- if (q=='t') {\r
- InfoT=1;\r
- } else if (q=='p') {\r
- InfoP=1;\r
- } else if (q=='m') {\r
- InfoM=1;\r
- } else if (q=='o') {\r
- InfoO=1;\r
- } else if (q=='0') {\r
- ; /* nothing */\r
- } else if (q=='f') {\r
- InfoF=1;\r
- } else {\r
- warnNoFL(eMsgd("unrecognized -info option \"%c\"",(int)*p));\r
- };\r
- };\r
-}\r
-\r
-#ifdef __USE_PROTOS\r
-static void pCGen(void) { CodeGen = FALSE; LexGen = FALSE; }\r
-static void pLGen(void) { LexGen = FALSE; }\r
-static void pXTGen(void){ MR_Inhibit_Tokens_h_Gen = TRUE; }\r
-static void pTGen(void) { TraceGen = TRUE; }\r
-static void pSGen(void) { GenExprSetsOpt = FALSE; }\r
-static void pPrt(void) { PrintOut = TRUE; pCGen(); pLGen(); }\r
-static void pPrtA(void) { PrintOut = TRUE; PrintAnnotate = TRUE; pCGen(); pLGen(); }\r
-static void pAst(void) { GenAST = TRUE; }\r
-static void pANSI(void) { GenANSI = TRUE; }\r
-static void pCr(void) { GenCR = TRUE; }\r
-static void pNOPURIFY(void) { PURIFY = FALSE; }\r
-/*static void pCt(void) { warnNoFL("-ct option is now the default"); }*/\r
-static void pLI(void) { GenLineInfo = TRUE; GenLineInfoMS = FALSE; } /* MR14 */\r
-static void pLIms(void) { GenLineInfo = TRUE; GenLineInfoMS = TRUE; } /* MR14 */\r
-static void pFr(char *s, char *t) {RemapFileName = t;}\r
-static void pFe(char *s, char *t) {ErrFileName = t;}\r
-static void pFl(char *s, char *t) {DlgFileName = t;}\r
-static void pFm(char *s, char *t) {ModeFileName = t;}\r
-static void pFt(char *s, char *t) {DefFileName = t;}\r
-\r
-static void pE1(void) { elevel = 1; }\r
-static void pE2(void) { elevel = 2; }\r
-static void pE3(void) { elevel = 3; }\r
-static void pEGen(void) { GenEClasseForRules = 1; }\r
-static void pDL(void)\r
- {\r
- DemandLookahead = 1;\r
- if ( GenCC ) {\r
- warnNoFL("-gk does not work currently in C++ mode; -gk turned off");\r
- DemandLookahead = 0;\r
- }\r
- }\r
-\r
-static void pAA(char *s,char *t) {MR_AmbAidRule = t;} /* MR11 */\r
-static void pAAm(char *s){MR_AmbAidMultiple = 1;} /* MR11 */\r
-static void pGHdr(void) { GenStdPccts = 1; }\r
-static void pFHdr(char *s, char *t) { stdpccts = t; pGHdr(); }\r
-static void pW1(void) { WarningLevel = 1; }\r
-static void pNewAST(void) { NewAST = 1; } /* MR13 */\r
-static void ptmakeInParser(void) { tmakeInParser = 1; } /* MR23 */\r
-static void pAlpha(void) { AlphaBetaTrace = 1; } /* MR14 */\r
-static void pMR_BlkErr(void) { MR_BlkErr = 1; } /* MR21 */\r
-static void pStdout(void) {UseStdout = 1; } /* MR6 */\r
-static void pW2(void) { WarningLevel = 2; }\r
-static void pCC(void) { GenCC = TRUE; }\r
-#else\r
-static void pCGen() { CodeGen = FALSE; LexGen = FALSE; }\r
-static void pLGen() { LexGen = FALSE; }\r
-static void pXTGen(){ MR_Inhibit_Tokens_h_Gen = TRUE; } /* MR14 */\r
-static void pTGen() { TraceGen = TRUE; }\r
-static void pSGen() { GenExprSetsOpt = FALSE; }\r
-static void pPrt() { PrintOut = TRUE; pCGen(); pLGen(); }\r
-static void pPrtA() { PrintOut = TRUE; PrintAnnotate = TRUE; pCGen(); pLGen(); }\r
-static void pAst() { GenAST = TRUE; }\r
-static void pANSI() { GenANSI = TRUE; }\r
-static void pCr() { GenCR = TRUE; }\r
-static void pNOPURIFY() { PURIFY = FALSE; }\r
-\r
-/*static void pCt() { warnNoFL("-ct option is now the default"); }*/\r
-static void pLI() { GenLineInfo = TRUE; GenLineInfoMS = FALSE; } /* MR14 */\r
-static void pLIms() { GenLineInfo = TRUE; GenLineInfoMS = TRUE; } /* MR14 */\r
-static void pFr(s,t) char *s, *t; {RemapFileName = t;}\r
-static void pFe(s,t) char *s, *t; {ErrFileName = t;}\r
-static void pFl(s,t) char *s, *t; {DlgFileName = t;}\r
-static void pFm(s,t) char *s, *t; {ModeFileName = t;}\r
-static void pFt(s,t) char *s, *t; {DefFileName = t;}\r
-\r
-static void pE1() { elevel = 1; }\r
-static void pE2() { elevel = 2; }\r
-static void pE3() { elevel = 3; }\r
-static void pEGen() { GenEClasseForRules = 1; }\r
-static void pDL()\r
- {\r
- DemandLookahead = 1;\r
- if ( GenCC ) {\r
- warnNoFL("-gk does not work currently in C++ mode; -gk turned off");\r
- DemandLookahead = 0;\r
- }\r
- }\r
-\r
-static void pAA(s,t) char *s; char *t; {MR_AmbAidRule = t;} /* MR11 BJS 20-Mar-98 */\r
-static void pAAm(s) char *s; {MR_AmbAidMultiple = 1;} /* MR11 BJS 20-Mar-98 */\r
-static void pGHdr() { GenStdPccts = 1; }\r
-static void pFHdr(s,t) char *s, *t; { stdpccts = t; pGHdr(); }\r
-static void pW1() { WarningLevel = 1; }\r
-static void pNewAST() { NewAST = 1; } /* MR13 */\r
-static void ptmakeInParser() { tmakeInParser = 1; } /* MR23 */\r
-static void pAlpha() { AlphaBetaTrace = 1; } /* MR14 */\r
-static void pMR_BlkErr() { MR_BlkErr = 1; } /* MR21 */\r
-static void pStdout() {UseStdout = 1; } /* MR6 */\r
-static void pW2() { WarningLevel = 2; }\r
-static void pCC() { GenCC = TRUE; }\r
-#endif\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pPre( char *s, char *t )\r
-#else\r
-pPre( s, t )\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- RulePrefix = t;\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pOut( char *s, char *t )\r
-#else\r
-pOut( s, t )\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- OutputDirectory = t;\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pPred( void )\r
-#else\r
-pPred( )\r
-#endif\r
-{\r
- warnNoFL("-pr is no longer used (predicates employed if present); see -prc, -mrhoist, -mrhoistk");\r
-/*\r
-** if ( DemandLookahead )\r
-** warnNoFL("-gk conflicts with -pr; -gk turned off");\r
-** DemandLookahead = 0;\r
-** HoistPredicateContext = 0;\r
-*/\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pPredCtx( char *s, char *t )\r
-#else\r
-pPredCtx(s,t)\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- if ( ci_strequ(t,"on")) HoistPredicateContext = 1;\r
- else if ( ci_strequ(t,"off")) HoistPredicateContext = 0;\r
- if ( DemandLookahead )\r
- {\r
- warnNoFL("-gk incompatible with semantic predicate usage; -gk turned off");\r
- DemandLookahead = 0;\r
- }\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pMRhoist( char *s, char *t )\r
-#else\r
-pMRhoist(s,t)\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- if ( ci_strequ(t,"on")) MRhoisting = 1;\r
- else if ( ci_strequ(t,"off")==0 ) MRhoisting = 0;\r
- if (MRhoisting) {\r
- fprintf(stderr,"Maintenance Release style hoisting enabled for predicates with lookahead depth = 1\n");\r
- fprintf(stderr," No longer considered experimental\n");\r
- fprintf(stderr," Can't consider suppression for predicates with lookahead depth > 1\n");\r
- fprintf(stderr," Implies -prc on but does *not* imply -mrhoistk for k>1 predicates\n");\r
- fprintf(stderr," This is a reminder, not a warning or error.\n");\r
- };\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pMRhoistk( char *s, char *t )\r
-#else\r
-pMRhoistk(s,t)\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- if ( ci_strequ(t,"on")) MRhoistingk = 1;\r
- else if ( ci_strequ(t,"off")==0 ) MRhoistingk = 0;\r
- if (MRhoistingk) {\r
- fprintf(stderr,"EXPERIMENTAL Maintenance Release style hoisting enabled\n");\r
- fprintf(stderr," Applies to predicates with lookahead depth > 1\n");\r
- fprintf(stderr," Implies -prc on and -mrhoist on\n");\r
- };\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-pTRes( char *s, char *t )\r
-#else\r
-pTRes( s, t )\r
-char *s;\r
-char *t;\r
-#endif\r
-{\r
- TreeResourceLimit = atoi(t);\r
- if ( TreeResourceLimit <= 0 )\r
- {\r
- warnNoFL("analysis resource limit (# of tree nodes) must be greater than 0");\r
- TreeResourceLimit = -1; /* set to no limit */\r
- }\r
-}\r
-\r
-Opt options[] = {\r
-#ifdef __cplusplus\r
- { "-CC", 0, (void (*)(...)) pCC, "Generate C++ output (default=FALSE)"},\r
- { "-ck", 1, (void (*)(...)) pCk, "Set compressed lookahead depth; fast approximate lookahead"},\r
- { "-cr", 0, (void (*)(...)) pCr, "Generate cross reference (default=FALSE)"},\r
- { "-e1", 0, (void (*)(...)) pE1, "Ambiguities/errors shown in low detail (default)"},\r
- { "-e2", 0, (void (*)(...)) pE2, "Ambiguities/errors shown in more detail"},\r
- { "-e3", 0, (void (*)(...)) pE3,\r
- "Ambiguities for k>1 grammars shown with exact tuples (not lookahead sets)"},\r
- { "-f", 1, (void (*)(...)) pFileList,"Read names of grammar files from specified file"}, /* MR14 */\r
- { "-fe", 1, (void (*)(...)) pFe, "Rename err.c"},\r
- { "-fh", 1, (void (*)(...)) pFHdr, "Rename stdpccts.h header (turns on -gh)"},\r
- { "-fl", 1, (void (*)(...)) pFl, "Rename lexical output--parser.dlg"},\r
- { "-fm", 1, (void (*)(...)) pFm, "Rename mode.h"},\r
- { "-fr", 1, (void (*)(...)) pFr, "Rename remap.h"},\r
- { "-ft", 1, (void (*)(...)) pFt, "Rename tokens.h"},\r
- { "-ga", 0, (void (*)(...)) pANSI, "Generate ANSI-compatible code (default=FALSE)"},\r
- { "-gc", 0, (void (*)(...)) pCGen, "Do not generate output parser code (default=FALSE)"},\r
- { "-gd", 0, (void (*)(...)) pTGen, "Generate code to trace rule invocation (default=FALSE)"},\r
- { "-ge", 0, (void (*)(...)) pEGen, "Generate an error class for each non-terminal (default=FALSE)"},\r
- { "-gh", 0, (void (*)(...)) pGHdr, "Generate stdpccts.h for non-ANTLR-generated-files to include"},\r
- { "-gk", 0, (void (*)(...)) pDL, "Generate parsers that delay lookahead fetches until needed"},\r
- { "-gl", 0, (void (*)(...)) pLI, "Generate line info about grammar actions in parser"},\r
- { "-glms", 0, (void (*)(...)) pLIms,"Like -gl but replace '\\' with '/' in #line filenames for MS C/C++ systems"},\r
- { "-gp", 1, (void (*)(...)) pPre, "Prefix all generated rule functions with a string"},\r
- { "-gs", 0, (void (*)(...)) pSGen, "Do not generate sets for token expression lists (default=FALSE)"},\r
- { "-gt", 0, (void (*)(...)) pAst, "Generate code for Abstract-Syntax-Trees (default=FALSE)"},\r
- { "-gx", 0, (void (*)(...)) pLGen, "Do not generate lexical (dlg-related) files (default=FALSE)"},\r
- { "-gxt",0, (void (*)(...)) pXTGen, "Do not generate tokens.h (default=FALSE)"},\r
- { "-k", 1, (void (*)(...)) pLLK, "Set full LL(k) lookahead depth (default==1)"},\r
- { "-o", 1, (void (*)(...)) pOut, OutputDirectoryOption},\r
- { "-p", 0, (void (*)(...)) pPrt, "Print out the grammar w/o actions (default=no)"},\r
- { "-pa", 0, (void (*)(...)) pPrtA, "Print out the grammar w/o actions & w/FIRST sets (default=no)"},\r
- { "-pr",0, (void (*)(...)) pPred, "no longer used; predicates employed if present"},\r
- { "-prc", 1, (void (*)(...)) pPredCtx,"Turn on/off computation of context for hoisted predicates"},\r
- { "-rl", 1, (void (*)(...)) pTRes, "Limit max # of tree nodes used by grammar analysis"},\r
- { "-stdout",0, (void (*)(...)) pStdout,"Send grammar.c/grammar.cpp to stdout"}, /* MR6 */\r
- { "-tab", 1, (void (*)(...)) pTab, "Width of tabs (1 to 8) for grammar.c/grammar.cpp files"}, /* MR6 */\r
- { "-w1", 0, (void (*)(...)) pW1, "Set the warning level to 1 (default)"},\r
- { "-w2", 0, (void (*)(...)) pW2, "Ambiguities yield warnings even if predicates or (...)? block"},\r
- { "-", 0, (void (*)(...)) pStdin, "Read grammar from stdin" },\r
- { "-mrhoist",1, (void (*)(...)) pMRhoist, /* MR9 */\r
- "Turn on/off k=1 Maintenance Release style hoisting"}, /* MR9 */\r
- { "-mrhoistk",1, (void (*)(...)) pMRhoistk, /* MR9 */\r
- "Turn on/off EXPERIMENTAL k>1 Maintenance Release style hoisting"}, /* MR13 */\r
- { "-aa" , 1, (void (*)(...)) pAA, "Ambiguity aid for a rule (rule name or line number)"}, /* MR11 */\r
- { "-aam" , 0, (void (*)(...)) pAAm,\r
- "Lookahead token may appear multiple times in -aa listing"}, /* MR11 */\r
- { "-aad" , 1, (void (*)(...)) pAAd,\r
- "Limits exp growth of -aa listing - default=1 (max=ck value)"}, /* MR11 */\r
- { "-info", 1, (void (*)(...)) pInfo,\r
- "Extra info: p=pred t=tnodes f=first/follow m=monitor o=orphans 0=noop"}, /* MR12 */\r
- { "-treport",1,(void (*)(...)) pTreport,\r
- "Report when tnode usage exceeds value during ambiguity resolution"}, /* MR11 */\r
- { "-newAST", 0, (void (*)(...)) pNewAST,\r
- "In C++ mode use \"newAST(...)\" rather than \"new AST(...)\""}, /* MR13 */\r
- { "-tmake", 0, (void (*)(...)) ptmakeInParser,\r
- "In C++ mode use parser's tmake method rather than \"ASTBase::tmake(...)\""}, /* MR23 */\r
- { "-alpha",0,(void (*)(...)) pAlpha,\r
- "Provide additional information for \"(alpha)? beta\" error messages"}, /* MR14 */\r
- { "-mrblkerr",0,(void (*)(...)) pMR_BlkErr, /* MR21 */\r
- "EXPERIMENTAL change to (...)* and (...)+ syntax error sets"}, /* MR21 */\r
- { "-nopurify",0,(void (*)(...)) pNOPURIFY,\r
- "Don't use the notorious PURIFY macro (replaced by MR23 initial value syntax) to zero return arguments of rules"}, /* MR23 */\r
- { "*", 0, (void (*)(...)) pFile, "" }, /* anything else is a file */\r
-#else\r
- { "-CC", 0, pCC, "Generate C++ output (default=FALSE)"},\r
- { "-cr", 0, pCr, "Generate cross reference (default=FALSE)"},\r
- { "-ck", 1, pCk, "Set compressed lookahead depth; fast approximate lookahead"},\r
- { "-e1", 0, pE1, "Ambiguities/errors shown in low detail (default)"},\r
- { "-e2", 0, pE2, "Ambiguities/errors shown in more detail"},\r
- { "-e3", 0, pE3, "Ambiguities for k>1 grammars shown with exact tuples (not lookahead sets)"},\r
- { "-f", 1, pFileList,"Read names of grammar files from specified file"}, /* MR14 */\r
- { "-fe", 1, pFe, "Rename err.c"},\r
- { "-fh", 1, pFHdr, "Rename stdpccts.h header (turns on -gh)"},\r
- { "-fl", 1, pFl, "Rename lexical output--parser.dlg"},\r
- { "-fm", 1, pFm, "Rename mode.h"},\r
- { "-fr", 1, pFr, "Rename remap.h"},\r
- { "-ft", 1, pFt, "Rename tokens.h"},\r
- { "-ga", 0, pANSI, "Generate ANSI-compatible code (default=FALSE)"},\r
- { "-gc", 0, pCGen, "Do not generate output parser code (default=FALSE)"},\r
- { "-gd", 0, pTGen, "Generate code to trace rule invocation (default=FALSE)"},\r
- { "-ge", 0, pEGen, "Generate an error class for each non-terminal (default=FALSE)"},\r
- { "-gh", 0, pGHdr, "Generate stdpccts.h for non-ANTLR-generated-files to include"},\r
- { "-gk", 0, pDL, "Generate parsers that delay lookahead fetches until needed"},\r
- { "-gl", 0, pLI, "Generate line info about grammar actions in C parser"},\r
- { "-glms", 0, pLIms,"Like -gl but replace '\\' with '/' in #line filenames for MS C/C++ systems"},\r
- { "-gp", 1, pPre, "Prefix all generated rule functions with a string"},\r
- { "-gs", 0, pSGen, "Do not generate sets for token expression lists (default=FALSE)"},\r
- { "-gt", 0, pAst, "Generate code for Abstract-Syntax-Trees (default=FALSE)"},\r
- { "-gx", 0, pLGen, "Do not generate lexical (dlg-related) files (default=FALSE)"},\r
- { "-gxt",0, pXTGen, "Do not generate tokens.h (default=FALSE)"},\r
- { "-k", 1, pLLK, "Set full LL(k) lookahead depth (default==1)"},\r
- { "-o", 1, pOut, OutputDirectoryOption},\r
- { "-p", 0, pPrt, "Print out the grammar w/o actions (default=no)"},\r
- { "-pa", 0, pPrtA, "Print out the grammar w/o actions & w/FIRST sets (default=no)"},\r
- { "-pr",0, pPred, "no longer used; predicates employed if present"},\r
- { "-prc", 1, pPredCtx,"Turn on/off computation of context for hoisted predicates"},\r
- { "-rl", 1, pTRes, "Limit max # of tree nodes used by grammar analysis"},\r
- { "-stdout",0, pStdout, "Send grammar.c/grammar.cpp to stdout"}, /* MR6 */\r
- { "-tab", 1, pTab, "Width of tabs (1 to 8) for grammar.c/grammar.cpp files"}, /* MR6 */\r
- { "-w1", 0, pW1, "Set the warning level to 1 (default)"},\r
- { "-w2", 0, pW2, "Ambiguities yield warnings even if predicates or (...)? block"},\r
- { "-mrhoist",1,pMRhoist, /* MR9 */\r
- "Turn on/off k=1 Maintenance Release style hoisting"}, /* MR9 */\r
- { "-mrhoistk",1,pMRhoistk, /* MR13 */\r
- "Turn on/off k>1 EXPERIMENTAL Maintenance Release style hoisting"}, /* MR13 */\r
- { "-aa" ,1,pAA, "Ambiguity aid for a rule (rule name or line number)"}, /* MR11 */\r
- { "-aam" ,0,pAAm,\r
- "Lookahead token may appear multiple times in -aa listing"}, /* MR11 */\r
- { "-aad" ,1,pAAd,\r
- "Limits exp growth of -aa listing - default=1 (max=ck value)"}, /* MR11 */\r
- { "-info",1,pInfo,\r
- "Extra info: p=pred t=tnodes f=first/follow m=monitor o=orphans 0=noop"}, /* MR11 */\r
- { "-treport",1,pTreport,\r
- "Report when tnode usage exceeds value during ambiguity resolution"}, /* MR11 */\r
- { "-newAST", 0, pNewAST,\r
- "In C++ mode use \"newAST(...)\" rather than \"new AST(...)\""}, /* MR13 */\r
- { "-tmake", 0, ptmakeInParser,\r
- "In C++ mode use parser's tmake method rather than \"ASTBase::tmake(...)\""}, /* MR23 */\r
- { "-alpha",0, pAlpha,\r
- "Provide additional information for \"(alpha)? beta\" error messages"}, /* MR14 */\r
- { "-mrblkerr",0,pMR_BlkErr, /* MR21 */\r
- "EXPERIMENTAL change to (...)* and (...)+ syntax error sets"}, /* MR21 */\r
- { "-nopurify",0,pNOPURIFY,\r
- "Don't use the notorious PURIFY macro (replaced by MR23 initial value syntax) to zero return arguments of rules"}, /* MR23 */\r
- { "-", 0, pStdin, "Read grammar from stdin" },\r
- { "*", 0, pFile, "" }, /* anything else is a file */\r
-#endif\r
- { NULL, 0, NULL }\r
- };\r
-\r
-void readDescr();\r
-void cleanUp();\r
-\r
-#ifdef __USE_PROTOS\r
-static void buildRulePtr( void );\r
-static void help( void );\r
-static void init( void );\r
-static void CompleteTokenSetRefs( void );\r
-static void ensure_no_C_file_collisions(char *);\r
-static void CompleteContextGuards(void);\r
-#else\r
-static void buildRulePtr( );\r
-static void help( );\r
-static void init( );\r
-static void CompleteTokenSetRefs( );\r
-static void ensure_no_C_file_collisions();\r
-static void CompleteContextGuards();\r
-#endif\r
-\r
-static void\r
-#ifdef __USE_PROTOS /* <BJS> */\r
-report_numericPredLabels(ActionNode *a)\r
-#else\r
-report_numericPredLabels(a)\r
-ActionNode *a;\r
-#endif\r
-{ /* MR10 */\r
- warnFL("numeric references to attributes (e.g. $i or $i.j) in semantic pred will be null during guess mode", /* MR10 */\r
- FileStr[a->file],a->line); /* MR10 */\r
-} /* MR10 */\r
-\r
- /* M a i n */\r
-\r
-int\r
-#ifdef __USE_PROTOS\r
-main( int argc, char *argv[] )\r
-#else\r
-main( argc, argv )\r
-int argc;\r
-char *argv[];\r
-#endif\r
-{\r
- int i;\r
- static char EPSTR[] = "[Ep]";\r
-\r
- Save_argc=argc; /* MR10 */\r
- Save_argv=argv; /* MR10 */\r
-\r
-/* malloc_debug(8);*/\r
-\r
-#ifdef SPECIAL_INITS\r
- special_inits(); /* MR1 */\r
-#endif\r
- fprintf(stderr, "Antlr parser generator Version %s 1989-2001\n", Version);\r
- if ( argc == 1 ) { help(); zzDIE; }\r
- ProcessArgs(argc-1, &(argv[1]), options);\r
-\r
-/* MR14 */ if (MR_AmbAidRule && AlphaBetaTrace) {\r
-/* MR14 */ fatal("Can't specify both -aa (ambiguity aid) and -alpha (\"(alpha)? beta\" aid)");\r
-/* MR14 */ }\r
-\r
- if (MRhoistingk) { /* MR13 */\r
- HoistPredicateContext=1; /* MR13 */\r
- MRhoisting=1; /* MR13 */\r
- }; /* MR13 */\r
- if (MRhoisting && ! HoistPredicateContext) {\r
-/*** warnNoFL("Using \"-mrhoist\" forces \"-prc on\""); ***/\r
- HoistPredicateContext=1;\r
- };\r
- if (HoistPredicateContext && ! MRhoisting) {\r
- warnNoFL("When using predicate context (-prc on) -mrhoist on is recommended");\r
- }\r
- /* Fix lookahead depth */\r
- /* Compressed lookahead must always be larger than or equal to full lookahead */\r
- if ( CLL_k < LL_k && CLL_k>0 )\r
- {\r
- warnNoFL("must have compressed lookahead >= full LL(k) lookahead (setting -ck to -k)");\r
- CLL_k = LL_k;\r
- }\r
- if ( CLL_k == -1 ) CLL_k = LL_k;\r
- OutputLL_k = CLL_k;\r
- if ( ((CLL_k-1)&CLL_k)!=0 ) { /* output ll(k) must be power of 2 */\r
- int n;\r
- for(n=1; n<CLL_k; n<<=1) {;}\r
- OutputLL_k = n;\r
- };\r
-\r
- if (MR_BlkErr) {\r
- warnNoFL("The -mrblkerr option is EXPERIMENTAL");\r
- if (LL_k > 1) {\r
- warnNoFL("The -mrblkerr option is designed only for k=1 ck=1 grammars");\r
- }\r
- };\r
-\r
- if ( ! ambAidDepthSpecified) {\r
- MR_AmbAidDepth=1;\r
- } else {\r
- if (MR_AmbAidDepth > CLL_k || MR_AmbAidDepth <= 0) {\r
- warnNoFL(eMsgd(\r
- "Ambiguity aid depth (\"-aad ...\") must be a number between 1 and max(k,ck)=%d",CLL_k));\r
- MR_AmbAidDepth=1;\r
- };\r
- if (MR_AmbAidDepth == 0) {\r
- MR_AmbAidDepth=2;\r
- };\r
- };\r
-\r
- if (MR_AmbAidRule != NULL) MR_AmbAidLine=atoi(MR_AmbAidRule);\r
-\r
- fpTrans = &(C_Trans[0]); /* Translate to C Language */\r
- fpJTrans = &(C_JTrans[0]);\r
- init();\r
- lexclass(LexStartSymbol);\r
-\r
- readDescr();\r
- LastTokenCounted = TokenNum;\r
- RemapForcedTokens();\r
- if ( CannotContinue ) {cleanUp(); zzDIE;}\r
- if ( GenCC && no_classes_found ) fatal("required grammar class not found (exiting...)");\r
- if ( WarningLevel>1 && HdrAction == NULL )\r
- warnNoFL("no #header action was found");\r
- if ( FoundAtOperator && ! FoundExceptionGroup) {\r
- warnNoFL("found the exception operator '@' - but no exception group was found");\r
- };\r
- EpToken = addTname(EPSTR); /* add imaginary token epsilon */\r
- set_orel(EpToken, &imag_tokens);\r
-\r
- /* this won't work for hand-built scanners since EofToken is not\r
- * known. Forces EOF to be token type 1.\r
- */\r
- set_orel(EofToken, &imag_tokens);\r
-\r
- set_size(NumWords(TokenNum-1));\r
-\r
- /* compute the set of all known token types\r
- * It represents the set of tokens from 1 to last_token_num + the\r
- * reserved positions above that (if any). Don't include the set of\r
- * imaginary tokens such as the token/error classes or EOF.\r
- */\r
- {\r
- set a;\r
- a = set_dup(reserved_positions);\r
- for (i=1; i<TokenNum; i++) { set_orel(i, &a); }\r
- all_tokens = set_dif(a, imag_tokens);\r
- set_free(a);\r
- }\r
-\r
- ComputeTokSets(); /* Compute #tokclass sets */\r
- CompleteTokenSetRefs(); /* Change complex nodes in syn diag */\r
- CompleteContextGuards(); /* MR13 */\r
-\r
- if ( CodeGen ) genDefFile(); /* create tokens.h */\r
- if ( LexGen ) genLexDescr(); /* create parser.dlg */\r
-\r
- if ( GenStdPccts )\r
- {\r
- FILE *f = fopen(OutMetaName(stdpccts), "w");\r
- if ( f==NULL ) {warnNoFL( eMsg1("can't create %s",OutMetaName(stdpccts)) );}\r
- else\r
- {\r
-#ifdef SPECIAL_FOPEN\r
- special_fopen_actions(OutMetaName(stdpccts)); /* MR1 */\r
-#endif\r
- if (strcmp(stdpccts,"stdpccts.h") == 0) { /* MR10 */\r
- genStdPCCTSIncludeFile(f,NULL); /* MR10 */\r
- } else { /* MR10 */\r
- genStdPCCTSIncludeFile(f,pcctsBaseName(stdpccts)); /* MR32 */\r
- };\r
- fclose(f);\r
- }\r
- }\r
-\r
- buildRulePtr(); /* create mapping from rule # to RuleBlk junction */\r
- ComputeErrorSets();\r
- FoLink( (Node *)SynDiag ); /* add follow links to end of all rules */\r
- \r
- if ( GenCR ) GenCrossRef( SynDiag );\r
-\r
- if ( CodeGen )\r
- {\r
- if ( SynDiag == NULL )\r
- {\r
- warnNoFL("no grammar description recognized");\r
- cleanUp();\r
- zzDIE;\r
- }\r
- else if ( !GenCC ) {\r
- ErrFile = fopen(OutMetaName(ErrFileName), "w");\r
- require(ErrFile != NULL, "main: can't open err file");\r
-#ifdef SPECIAL_FOPEN\r
- special_fopen_actions(OutMetaName(ErrFileName)); /* MR1 */\r
-#endif\r
- NewSetWd();\r
- GenErrHdr();\r
- TRANS(SynDiag); /* Translate to the target language */\r
- DumpSetWd();\r
- DumpRemainingTokSets();\r
- fclose( ErrFile );\r
- }\r
- else {\r
- strcpy(Parser_h_Name, CurrentClassName);\r
- strcat(Parser_h_Name, ".h");\r
- strcpy(Parser_c_Name, CurrentClassName);\r
- strcat(Parser_c_Name, CPP_FILE_SUFFIX);\r
- ensure_no_C_file_collisions(Parser_c_Name);\r
- Parser_h = fopen(OutMetaName(Parser_h_Name), "w");\r
- require(Parser_h != NULL, "main: can't open class Parserx.h file");\r
-#ifdef SPECIAL_FOPEN\r
- special_fopen_actions(OutMetaName(Parser_h_Name)); /* MR1 */\r
-#endif\r
- Parser_c = fopen(OutMetaName(Parser_c_Name), "w");\r
- require(Parser_c != NULL, "main: can't open class Parserx.c file");\r
-#ifdef SPECIAL_FOPEN\r
- special_fopen_actions(OutMetaName(Parser_c_Name)); /* MR1 */\r
-#endif\r
- GenParser_h_Hdr();\r
- if ( class_before_actions != NULL )\r
- {\r
- ListNode *p;\r
- for (p = class_before_actions->next; p!=NULL; p=p->next)\r
- {\r
- UserAction *ua = (UserAction *)p->elem;\r
- dumpAction( ua->action, Parser_h, 0, ua->file, ua->line, 1);\r
- }\r
- }\r
- GenParser_c_Hdr();\r
- fprintf(Parser_h, "protected:\n"); /* MR20 */\r
- NewSetWd();\r
- TRANS(SynDiag); /* Translate to the target language */\r
- DumpSetWd();\r
- GenRuleMemberDeclarationsForCC(Parser_h, SynDiag);\r
- if ( class_after_actions != NULL )\r
- {\r
- ListNode *p;\r
- for (p = class_after_actions->next; p!=NULL; p=p->next)\r
- {\r
- UserAction *ua = (UserAction *)p->elem;\r
- dumpAction( ua->action, Parser_h, 0, ua->file, ua->line, 1);\r
- }\r
- }\r
- DumpRemainingTokSets();\r
- fprintf(Parser_h, "};\n");\r
- fprintf(Parser_h, "\n#endif /* %s_h */\n", CurrentClassName);\r
- fclose( Parser_h );\r
- fclose( Parser_c );\r
- }\r
- }\r
-\r
- MR_orphanRules(stderr);\r
- if (LTinTokenAction && WarningLevel >= 2) {\r
- if (GenCC) {\r
- warnNoFL("At least one <<action>> following a token match contains a reference to LT(...)\n this will reference the immediately preceding token,\n not the one which follows as is the case with semantic predicates.");\r
- }\r
- warnNoFL("At least one <<action>> following a token match contains a reference to LA(...) or LATEXT(...)\n this will reference the immediately preceding token,\n not the one which follows as is the case with semantic predicates.");\r
- }\r
-\r
- if ( PrintOut )\r
- {\r
- if ( SynDiag == NULL ) {warnNoFL("no grammar description recognized");}\r
- else PRINT(SynDiag);\r
- }\r
-\r
-#ifdef DBG_LL1\r
-#endif\r
- GenRemapFile(); /* create remap.h */\r
-/* MR10 */ if (FoundGuessBlk) {\r
-#ifdef __cplusplus__\r
-/* MR10 */ list_apply(NumericPredLabels, (void (*)(void *))report_numericPredLabels);\r
-#else\r
-#ifdef __USE_PROTOS\r
-/* MR10 */ list_apply(NumericPredLabels, (void (*)(void *))report_numericPredLabels);\r
-#else\r
-/* MR10 */ list_apply(NumericPredLabels,report_numericPredLabels);\r
-#endif\r
-#endif\r
-/* MR10 */ };\r
-\r
- if (InfoT && TnodesAllocated > 0) {\r
- if (TnodesPeak > 10000) {\r
- fprintf(stdout,"\nTree Nodes: peak %dk created %dk lost %d\n",\r
- (TnodesPeak/1000),\r
- (TnodesAllocated/1000),\r
- TnodesInUse-tnodes_used_in_guard_predicates_etc);\r
- } else {\r
- fprintf(stdout,"\nTree Nodes: peak %d created %d lost %d\n",\r
- TnodesPeak,\r
- TnodesAllocated,\r
- TnodesInUse-tnodes_used_in_guard_predicates_etc);\r
- };\r
- };\r
- if (InfoF) {\r
- DumpFcache();\r
- };\r
- if (MR_skipped_e3_report) {\r
- fprintf(stderr,"note: use -e3 to get exact information on ambiguous tuples\n");\r
- };\r
- if (MR_BadExprSets != 0) {\r
- fprintf(stderr,"note: Unreachable C or C++ code was generated for empty expression sets,\n");\r
- fprintf(stderr," probably due to undefined rules or infinite left recursion.\n");\r
- fprintf(stderr," To locate: search the generated code for \"empty set expression\"\n");\r
- };\r
- if (MR_AmbAidRule != NULL && MR_matched_AmbAidRule==0) {\r
- RuleEntry *q = (RuleEntry *) hash_get(Rname,MR_AmbAidRule);\r
- if (MR_AmbAidLine == 0 && q == NULL) {\r
- warnNoFL(eMsg2("there is no rule \"%s\" so \"-aa %s\" will never match",\r
- MR_AmbAidRule,MR_AmbAidRule));\r
- } else {\r
- warnNoFL(eMsg1("there was no ambiguity that matched \"-aa %s\"",MR_AmbAidRule));\r
- };\r
- };\r
- if (AlphaBetaTrace) {\r
-\r
- if (MR_AlphaBetaMessageCount == 0) {\r
- fprintf(stderr,"note: there were no messages about \"(alpha)? beta\" blocks added to the generated code\n");\r
- } else {\r
- fprintf(stderr,"note: there were %d messages about \"(alpha)? beta\" blocks added to the generated code\n",\r
- MR_AlphaBetaMessageCount);\r
- }\r
-\r
- if (set_null(MR_CompromisedRules)) {\r
- fprintf(stderr,"note: the list of rules with compromised follow sets is empty\n");\r
- } else {\r
- fprintf(stderr,"note: the following is a list of rules which *may* have incorrect\n");\r
- fprintf(stderr," follow sets computed as a result of an \"(alpha)? beta\" block\n");\r
- fprintf(stderr,"\n");\r
- MR_dumpRuleSet(MR_CompromisedRules);\r
- fprintf(stderr,"\n");\r
- }\r
- }\r
- cleanUp();\r
- exit(PCCTS_EXIT_SUCCESS);\r
- return 0; /* MR11 make compilers happy */ \r
-}\r
-\r
-static void \r
-#ifdef __USE_PROTOS \r
-init( void )\r
-#else\r
-init( )\r
-#endif\r
-{\r
- SignalEntry *q;\r
-\r
- Tname = newHashTable();\r
- Rname = newHashTable();\r
- Fcache = newHashTable();\r
- Tcache = newHashTable();\r
- Sname = newHashTable();\r
- Pname = newHashTable(); /* MR11 */\r
-\r
- /* Add default signal names */\r
- q = (SignalEntry *)hash_add(Sname,\r
- "NoViableAlt",\r
- (Entry *)newSignalEntry("NoViableAlt"));\r
- require(q!=NULL, "cannot alloc signal entry");\r
- q->signum = sigNoViableAlt;\r
- q = (SignalEntry *)hash_add(Sname,\r
- "MismatchedToken",\r
- (Entry *)newSignalEntry("MismatchedToken"));\r
- require(q!=NULL, "cannot alloc signal entry");\r
- q->signum = sigMismatchedToken;\r
- q = (SignalEntry *)hash_add(Sname,\r
- "NoSemViableAlt",\r
- (Entry *)newSignalEntry("NoSemViableAlt"));\r
- require(q!=NULL, "cannot alloc signal entry");\r
- q->signum = sigNoSemViableAlt;\r
- \r
- reserved_positions = empty;\r
- all_tokens = empty;\r
- imag_tokens = empty;\r
- tokclasses = empty;\r
- TokenStr = (char **) calloc(TSChunk, sizeof(char *));\r
- require(TokenStr!=NULL, "main: cannot allocate TokenStr");\r
- FoStack = (int **) calloc(CLL_k+1, sizeof(int *));\r
- require(FoStack!=NULL, "main: cannot allocate FoStack");\r
- FoTOS = (int **) calloc(CLL_k+1, sizeof(int *));\r
- require(FoTOS!=NULL, "main: cannot allocate FoTOS");\r
- Cycles = (ListNode **) calloc(CLL_k+1, sizeof(ListNode *));\r
- require(Cycles!=NULL, "main: cannot allocate Cycles List");\r
- MR_CompromisedRules=empty; /* MR14 */\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-help( void )\r
-#else\r
-help( )\r
-#endif\r
-{\r
- Opt *p = options;\r
- fprintf(stderr, "antlr [options] f1 f2 ... fn\n");\r
- while ( *(p->option) != '*' )\r
- {\r
- fprintf(stderr, " %-9s%s %s\n",\r
- p->option,\r
- (p->arg)?"___":" ",\r
- p->descr);\r
- p++;\r
- }\r
-}\r
-\r
-/* The RulePtr array is filled in here. RulePtr exists primarily\r
- * so that sets of rules can be maintained for the FOLLOW caching\r
- * mechanism found in rJunc(). RulePtr maps a rule num from 1 to n\r
- * to a pointer to its RuleBlk junction where n is the number of rules.\r
- */\r
-static void\r
-#ifdef __USE_PROTOS\r
-buildRulePtr( void )\r
-#else\r
-buildRulePtr( )\r
-#endif\r
-{\r
- int r=1;\r
- Junction *p = SynDiag;\r
- RulePtr = (Junction **) calloc(NumRules+1, sizeof(Junction *));\r
- require(RulePtr!=NULL, "cannot allocate RulePtr array");\r
- \r
- while ( p!=NULL )\r
- {\r
- require(r<=NumRules, "too many rules???");\r
- RulePtr[r++] = p;\r
- p = (Junction *)p->p2;\r
- }\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-dlgerror(const char *s)\r
-#else\r
-dlgerror(s)\r
-char *s;\r
-#endif\r
-{\r
- fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);\r
- fprintf(stderr, " lexical error: %s (text was '%s')\n",\r
- ((s == NULL) ? "Lexical error" : s), zzlextext);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-readDescr( void )\r
-#else\r
-readDescr( )\r
-#endif\r
-{\r
- zzerr = dlgerror;\r
- input = NextFile();\r
- if ( input==NULL ) fatal("No grammar description found (exiting...)");\r
- ANTLR(grammar(), input);\r
- tnodes_used_in_guard_predicates_etc=TnodesInUse; /* MR10 */\r
-}\r
-\r
-FILE *\r
-#ifdef __USE_PROTOS\r
-NextFile( void )\r
-#else\r
-NextFile( )\r
-#endif\r
-{\r
- FILE *f;\r
-\r
- for (;;)\r
- {\r
- CurFile++;\r
- if ( CurFile >= NumFiles ) return(NULL);\r
- if ( ci_strequ(FileStr[CurFile],"stdin")) return stdin;\r
- f = fopen(FileStr[CurFile], "r");\r
- if ( f == NULL )\r
- {\r
- warnNoFL( eMsg1("file %s doesn't exist; ignored", FileStr[CurFile]) );\r
- }\r
- else\r
- {\r
- return(f);\r
- }\r
- }\r
-}\r
-\r
-/*\r
- * Return a string corresponding to the output file name associated\r
- * with the input file name passed in.\r
- *\r
- * Observe the following rules:\r
- *\r
- * f.e --> f".c"\r
- * f --> f".c"\r
- * f. --> f".c"\r
- * f.e.g --> f.e".c"\r
- *\r
- * Where f,e,g are arbitrarily long sequences of characters in a file\r
- * name.\r
- *\r
- * In other words, if a ".x" appears on the end of a file name, make it\r
- * ".c". If no ".x" appears, append ".c" to the end of the file name.\r
- *\r
- * C++ mode using .cpp not .c.\r
- *\r
- * Use malloc() for new string.\r
- */\r
-\r
-char *\r
-#ifdef __USE_PROTOS\r
-outname( char *fs )\r
-#else\r
-outname( fs )\r
-char *fs;\r
-#endif\r
-{\r
- if ( GenCC) {\r
- return outnameX(fs,CPP_FILE_SUFFIX);\r
- } else {\r
- return outnameX(fs,".c");\r
- };\r
-}\r
-\r
-char *\r
-#ifdef __USE_PROTOS\r
-outnameX( char *fs ,char *suffix)\r
-#else\r
-outnameX( fs , suffix )\r
-char *fs;\r
-char *suffix;\r
-#endif\r
-{\r
- static char buf[MaxFileName+1];\r
- char *p;\r
- require(fs!=NULL&&*fs!='\0', "outname: NULL filename");\r
-\r
- p = buf;\r
- strcpy(buf, fs);\r
- while ( *p != '\0' ) {p++;} /* Stop on '\0' */\r
- while ( *p != '.' && p != buf ) {--p;} /* Find '.' */\r
- if ( p != buf ) *p = '\0'; /* Found '.' */\r
- require(strlen(buf) + 2 < (size_t)MaxFileName, "outname: filename too big");\r
- strcat(buf,suffix);\r
- return( buf );\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-fatalFL( char *err_, char *f, int l )\r
-#else\r
-fatalFL( err_, f, l )\r
-char *err_;\r
-char *f;\r
-int l;\r
-#endif\r
-{\r
- fprintf(stderr, ErrHdr, f, l);\r
- fprintf(stderr, " %s\n", err_);\r
- cleanUp();\r
- exit(PCCTS_EXIT_FAILURE);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-fatal_intern( char *err_, char *f, int l )\r
-#else\r
-fatal_intern( err_, f, l )\r
-char *err_;\r
-char *f;\r
-int l;\r
-#endif\r
-{\r
- fprintf(stderr, ErrHdr, f, l);\r
- fprintf(stderr, " #$%%*&@# internal error: %s\n", err_);\r
- fprintf(stderr, ErrHdr, f, l);\r
- fprintf(stderr, " [complain to nearest government official\n");\r
- fprintf(stderr, ErrHdr, f, l);\r
- fprintf(stderr, " or send hate-mail to parrt@parr-research.com;\n");\r
- fprintf(stderr, ErrHdr, f, l);\r
- fprintf(stderr, " please pray to the ``bug'' gods that there is a trival fix.]\n");\r
- cleanUp();\r
- exit(PCCTS_EXIT_FAILURE);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-cleanUp( void )\r
-#else\r
-cleanUp( )\r
-#endif\r
-{\r
- if ( DefFile != NULL) fclose( DefFile );\r
-}\r
-\r
-/* sprintf up to 3 strings */\r
-char *\r
-#ifdef __USE_PROTOS\r
-eMsg3( char *s, char *a1, char *a2, char *a3 )\r
-#else\r
-eMsg3( s, a1, a2, a3 )\r
-char *s;\r
-char *a1;\r
-char *a2;\r
-char *a3;\r
-#endif\r
-{\r
- static char buf[250]; /* DANGEROUS as hell !!!!!! */\r
- \r
- sprintf(buf, s, a1, a2, a3);\r
- return( buf );\r
-}\r
-\r
-/* sprintf a decimal */\r
-char *\r
-#ifdef __USE_PROTOS\r
-eMsgd( char *s, int d )\r
-#else\r
-eMsgd( s, d )\r
-char *s;\r
-int d;\r
-#endif\r
-{\r
- static char buf[250]; /* DANGEROUS as hell !!!!!! */\r
- \r
- sprintf(buf, s, d);\r
- return( buf );\r
-}\r
-\r
-char *\r
-#ifdef __USE_PROTOS\r
-eMsgd2( char *s, int d1,int d2)\r
-#else\r
-eMsgd2( s, d1, d2 )\r
-char *s;\r
-int d1;\r
-int d2;\r
-#endif\r
-{\r
- static char buf[250]; /* DANGEROUS as hell !!!!!! */\r
- \r
- sprintf(buf, s, d1, d2);\r
- return( buf );\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-s_fprT( FILE *f, set e )\r
-#else\r
-s_fprT( f, e )\r
-FILE *f;\r
-set e;\r
-#endif\r
-{\r
- register unsigned *p;\r
- unsigned *q;\r
-\r
- if ( set_nil(e) ) return;\r
- if ( (q=p=set_pdq(e)) == NULL ) fatal_internal("Can't alloc space for set_pdq");\r
- fprintf(f, "{");\r
- while ( *p != nil )\r
- {\r
- fprintf(f, " %s", TerminalString(*p));\r
- p++;\r
- }\r
- fprintf(f, " }");\r
- free((char *)q);\r
-}\r
-\r
-/* Return the token name or regular expression for a token number. */\r
-char *\r
-#ifdef __USE_PROTOS\r
-TerminalString( int token )\r
-#else\r
-TerminalString( token )\r
-int token;\r
-#endif\r
-{\r
- int j;\r
- static char imag_name[20];\r
-\r
- /* look in all lexclasses for the token */\r
- if ( TokenString(token) != NULL ) return TokenString(token);\r
- for (j=0; j<NumLexClasses; j++)\r
- {\r
- lexmode(j);\r
- if ( ExprString(token) != NULL ) return ExprString(token);\r
- }\r
-\r
- if (1) {\r
- sprintf(imag_name,"UnknownToken#%d",token); /* MR13 */\r
- return imag_name; /* MR13 */\r
- }\r
-\r
- require(j<NumLexClasses, eMsgd("No label or expr for token %d",token));\r
- return "invalid";\r
-}\r
-\r
- /* S i m p l e I n t S t a c k */\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-pushint( int i )\r
-#else\r
-pushint( i )\r
-int i;\r
-#endif\r
-{\r
- require(isp>0, "pushint: stack overflow");\r
- istack[--isp] = i;\r
-}\r
-\r
-int\r
-#ifdef __USE_PROTOS\r
-popint( void )\r
-#else\r
-popint( )\r
-#endif\r
-{\r
- require(isp<MAX_INT_STACK, "popint: stack underflow");\r
- return istack[isp++];\r
-}\r
-\r
-int\r
-#ifdef __USE_PROTOS\r
-istacksize( void )\r
-#else\r
-istacksize( )\r
-#endif\r
-{\r
- return MAX_INT_STACK-isp;\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-istackreset( void )\r
-#else\r
-istackreset( )\r
-#endif\r
-{\r
- isp = MAX_INT_STACK;\r
-}\r
-\r
-int\r
-#ifdef __USE_PROTOS\r
-istackempty( void )\r
-#else\r
-istackempty( )\r
-#endif\r
-{\r
- return isp==MAX_INT_STACK;\r
-}\r
-\r
-int\r
-#ifdef __USE_PROTOS\r
-topint( void )\r
-#else\r
-topint( )\r
-#endif\r
-{\r
- require(isp<MAX_INT_STACK, "topint: stack underflow");\r
- return istack[isp];\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-ProcessArgs( int argc, char **argv, Opt *options )\r
-#else\r
-ProcessArgs( argc, argv, options )\r
-int argc;\r
-char **argv;\r
-Opt *options;\r
-#endif\r
-{\r
- Opt *p;\r
- require(argv!=NULL, "ProcessArgs: command line NULL");\r
-\r
- while ( argc-- > 0 )\r
- {\r
- p = options;\r
- while ( p->option != NULL )\r
- {\r
- if ( strcmp(p->option, "*") == 0 ||\r
- ci_strequ(p->option, *argv) == 1 )\r
- {\r
- if ( p->arg )\r
- {\r
-/* MR9 26-Sep-97 Check for argv valid */\r
- if (argc-- > 0) {\r
- (*p->process)( *argv, *(argv+1) );\r
- argv++;\r
- } else {\r
-fprintf(stderr,"error: required argument for option %s omitted\n",*argv);\r
-exit(PCCTS_EXIT_FAILURE);\r
- };\r
- }\r
- else\r
- (*p->process)( *argv );\r
- break;\r
- }\r
- p++;\r
- }\r
- argv++;\r
- }\r
-}\r
-\r
-static void \r
-#ifdef __USE_PROTOS\r
-CompleteContextGuards(void)\r
-#else\r
-CompleteContextGuards()\r
-#endif\r
-{\r
- ListNode * p;\r
- Predicate * pred;\r
-\r
- if (ContextGuardPredicateList == NULL) return;\r
-\r
- for (p=ContextGuardPredicateList->next; p != NULL; p=p->next) {\r
- pred=(Predicate *)p->elem;\r
- recomputeContextGuard(pred);\r
- }\r
-}\r
-\r
-/* Go back into the syntax diagram and compute all meta tokens; i.e.\r
- * turn all '.', ranges, token class refs etc... into actual token sets\r
- */\r
-static void\r
-#ifdef __USE_PROTOS\r
-CompleteTokenSetRefs(void)\r
-#else\r
-CompleteTokenSetRefs()\r
-#endif\r
-{\r
- ListNode *p;\r
-\r
- if ( MetaTokenNodes==NULL ) return;\r
- for (p = MetaTokenNodes->next; p!=NULL; p=p->next)\r
- {\r
- set a,b;\r
-\r
- TokNode *q = (TokNode *)p->elem;\r
- if ( q->wild_card )\r
- {\r
- q->tset = all_tokens;\r
- }\r
- else if ( q->tclass!=NULL )\r
- {\r
- if ( q->complement ) q->tset = set_dif(all_tokens, q->tclass->tset);\r
- else q->tset = q->tclass->tset;\r
- }\r
- else if ( q->upper_range!=0 )\r
- {\r
- /* we have a range on our hands: make a set from q->token .. q->upper_range */\r
- int i;\r
- a = empty;\r
- for (i=q->token; i<=q->upper_range; i++) { set_orel(i, &a); } /* MR13 */\r
-\r
-/* MR13 */ if (q->complement) {\r
-/* MR13 */ q->tset = set_dif(all_tokens, a);\r
-/* MR13 */ set_free(a);\r
-/* MR13 */ } else {\r
-/* MR13 */ q->tset = a;\r
-/* MR13 */ }\r
-\r
- }\r
-\r
- /* at this point, it can only be a complemented single token */\r
- else if ( q->complement )\r
- {\r
- a = set_of(q->token);\r
- b = set_dif(all_tokens, a);\r
- set_free(a);\r
- q->tset=b;\r
- }\r
- else fatal("invalid meta token");\r
- }\r
-}\r
-\r
-/* MR10: Jeff Vincent\r
- MR10: Changed to remove directory information from n only if\r
- MR10: if OutputDirectory was changed by user (-o option)\r
-*/\r
-\r
-char *\r
-#ifdef __USE_PROTOS\r
-OutMetaName(char *n)\r
-#else\r
-OutMetaName(n)\r
-char *n;\r
-#endif\r
-{ \r
- static char *dir_sym = DirectorySymbol;\r
- static char newname[MaxFileName+1];\r
- char *p;\r
-\r
- /* If OutputDirectory is same as TopDirectory (platform default) then leave n alone. */\r
- if (strcmp(OutputDirectory, TopDirectory) == 0) /* TopDirectory is "." on Unix. */\r
- return n;\r
-\r
- /* p will point to filename without path information */\r
- if ((p = strrchr(n, *dir_sym)) != NULL) /* Directory symbol is "/" on Unix. */\r
- p++;\r
- else\r
- p = n;\r
-\r
- /* Copy new output directory into newname[] */\r
- strcpy(newname, OutputDirectory);\r
-\r
- /* if new output directory does not have trailing dir_sym, add it! */\r
- if (newname[strlen(newname)-1] != *dir_sym) {\r
- strcat(newname, dir_sym);\r
- }\r
- strcat(newname, p);\r
- return newname;\r
-}\r
-\r
-char *\r
-#ifdef __USE_PROTOS\r
-pcctsBaseName(char *n) /* MR32 */\r
-#else\r
-pcctsBaseName(n)\r
-char *n;\r
-#endif\r
-{\r
- static char newname[MaxFileName+1];\r
- static char* dir_sym = DirectorySymbol;\r
- int count = 0;\r
- char *p;\r
-\r
- p = n;\r
-\r
- while ( *p != '\0' ) {p++;} /* go to end of string */\r
- while ( (*p != *dir_sym) && (p != n) ) {--p;} /* Find last DirectorySymbol */\r
- while ( *p == *dir_sym) p++; /* step forward if we're on a dir symbol */\r
- while ( *p != '\0' && *p != '.')\r
- {\r
- newname[count++] = *p;\r
- p++;\r
- } /* create a new name */\r
- newname[count] = '\0';\r
- return newname;\r
-}\r
-\r
-static void\r
-#ifdef __USE_PROTOS\r
-ensure_no_C_file_collisions(char *class_c_file)\r
-#else\r
-ensure_no_C_file_collisions(class_c_file)\r
-char *class_c_file;\r
-#endif\r
-{\r
- int i;\r
-\r
- for (i=0; i<NumFiles; i++)\r
- {\r
-\r
-#ifdef PCCTS_CASE_INSENSITIVE_FILE_NAME\r
- /* assume that file names are case insensitive */\r
- if ( STRICMP(outname(FileStr[i]), class_c_file)==0 )\r
-#else\r
- if ( strcmp(outname(FileStr[i]), class_c_file)==0 )\r
-#endif\r
- {\r
- fatal(eMsg1("class def output file conflicts with parser output file: %s",\r
- outname(FileStr[i])));\r
- }\r
- }\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-warnNoFL(char *err)\r
-#else\r
-warnNoFL(err)\r
-char *err;\r
-#endif\r
-{\r
- fprintf(stderr, "warning: %s\n", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-warnFL(char *err,char *f,int l)\r
-#else\r
-warnFL(err,f,l)\r
-char *f;\r
-int l;\r
-char *err;\r
-#endif\r
-{\r
- fprintf(stderr, ErrHdr, f, l); \r
- fprintf(stderr, " warning: %s\n", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-warn(char *err) \r
-#else\r
-warn(err) \r
-char *err;\r
-#endif\r
-{\r
- /* back up the file number if we hit an error at the end of the last file */\r
- if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;\r
- fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);\r
- fprintf(stderr, " warning: %s\n", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-warnNoCR( char *err )\r
-#else\r
-warnNoCR( err ) \r
-char *err;\r
-#endif\r
-{\r
- /* back up the file number if we hit an error at the end of the last file */\r
- if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;\r
- fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);\r
- fprintf(stderr, " warning: %s", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-errNoFL(char *err)\r
-#else\r
-errNoFL(err)\r
-char *err;\r
-#endif\r
-{\r
- fprintf(stderr, "error: %s\n", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-errFL(char *err,char *f,int l)\r
-#else\r
-errFL(err,f,l)\r
-char *err;\r
-char *f;\r
-int l;\r
-#endif\r
-{\r
- fprintf(stderr, ErrHdr, f, l); \r
- fprintf(stderr, " error: %s\n", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-err(char *err) \r
-#else\r
-err(err) \r
-char *err;\r
-#endif\r
-{\r
- /* back up the file number if we hit an error at the end of the last file */\r
- if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;\r
- fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);\r
- fprintf(stderr, " error: %s\n", err);\r
-}\r
-\r
-void\r
-#ifdef __USE_PROTOS\r
-errNoCR( char *err ) \r
-#else\r
-errNoCR( err ) \r
-char *err;\r
-#endif\r
-{\r
- /* back up the file number if we hit an error at the end of the last file */\r
- if ( CurFile >= NumFiles && CurFile >= 1 ) CurFile--;\r
- fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);\r
- fprintf(stderr, " error: %s", err);\r
-}\r
-\r
-UserAction *\r
-#ifdef __USE_PROTOS\r
-newUserAction(char *s)\r
-#else\r
-newUserAction(s)\r
-char *s;\r
-#endif\r
-{\r
- UserAction *ua = (UserAction *) calloc(1, sizeof(UserAction));\r
- require(ua!=NULL, "cannot allocate UserAction");\r
-\r
- ua->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));\r
- strcpy(ua->action, s);\r
- return ua;\r
-}\r
-\r
-/* Added by TJP September 1994 */\r
-/* Take in file.h and return file_h; names w/o '.'s are left alone */\r
-char *\r
-#ifdef __USE_PROTOS\r
-gate_symbol(char *name)\r
-#else\r
-gate_symbol(name)\r
-char *name;\r
-#endif\r
-{\r
- static char buf[100];\r
- char *p;\r
- sprintf(buf, "%s", name);\r
-\r
- for (p=buf; *p!='\0'; p++)\r
- {\r
- if ( *p=='.' ) *p = '_';\r
- }\r
- return buf;\r
-}\r
-\r
-char *\r
-#ifdef __USE_PROTOS\r
-makeAltID(int blockid, int altnum)\r
-#else\r
-makeAltID(blockid, altnum)\r
-int blockid;\r
-int altnum;\r
-#endif\r
-{\r
- static char buf[100];\r
- char *p;\r
- sprintf(buf, "_blk%d_alt%d", blockid, altnum);\r
- p = (char *)malloc(strlen(buf)+1);\r
- strcpy(p, buf);\r
- return p;\r
-}\r