main.c
来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 1,748 行 · 第 1/4 页
C
1,748 行
/*
* main.c -- main program for PCCTS ANTLR.
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
/* To set a breakpoint just before exit look for "cleanUp". */
/* To set a breakpoint for fatal error look for "fatal_intern" */
#include <stdio.h>
#include "pcctscfg.h"
#include "stdpccts.h"
#define MAX_INT_STACK 50
static int istack[MAX_INT_STACK]; /* Int stack */
static int isp = MAX_INT_STACK;
static int DontAcceptFiles = 0; /* if stdin, don't read files */
static int DontAcceptStdin = 0; /* if files seen first, don't accept stdin */
static int tnodes_used_in_guard_predicates_etc; /* MR10 */
/* C m d - L i n e O p t i o n S t r u c t & F u n c s */
typedef struct _Opt {
char *option;
int arg;
#ifdef __cplusplus
void (*process)(...);
#else
void (*process)();
#endif
char *descr;
} Opt;
#ifdef __USE_PROTOS
extern void ProcessArgs(int, char **, Opt *);
#else
extern void ProcessArgs();
#endif
#ifdef __USE_PROTOS
int ci_strequ(char *a,char *b)
#else
int ci_strequ(a,b)
char *a;
char *b;
#endif
{
for ( ;*a != 0 && *b != 0; a++, b++) {
if (toupper(*a) != toupper(*b)) return 0;
}
return (*a == *b);
}
static void
#ifdef __USE_PROTOS
pStdin( void )
#else
pStdin( )
#endif
{
if ( DontAcceptStdin )
{
warnNoFL("'-' (stdin) ignored as files were specified first");
return;
}
require(NumFiles<MaxNumFiles,"exceeded max # of input files");
FileStr[NumFiles++] = "stdin";
DontAcceptFiles = 1;
}
static void
#ifdef __USE_PROTOS
pFile( char *s )
#else
pFile( s )
char *s;
#endif
{
if ( *s=='-' ) { warnNoFL( eMsg1("invalid option: '%s'",s) ); return; }
if ( DontAcceptFiles )
{
warnNoFL(eMsg1("file '%s' ignored as '-' (stdin option) was specified first",s));
return;
}
require(NumFiles<MaxNumFiles,"exceeded max # of input files");
FileStr[NumFiles++] = s;
DontAcceptStdin = 1;
}
/* MR14
Allow input to be a file containing a list of files
Bernard Giroud (b_giroud@decus.ch)
*/
static void
#ifdef __USE_PROTOS
pFileList( char *s, char *t )
#else
pFileList( s, t )
char *s;
char *t;
#endif
{
#define MaxFLArea 1024
FILE *fl;
static char Fn_in_Fl[MaxFLArea] = "";
char one_fn[MaxFileName];
char *flp = &Fn_in_Fl[0];
int fnl, left = MaxFLArea, i;
if ( *t=='-' ) { warnNoFL( eMsg1("invalid option: '%s'",t) ); return; }
if ( DontAcceptFiles )
{
warnNoFL(eMsg1("file '%s' ignored as '-' (stdin option) was specified first",t));
return;
}
if ((fl = fopen(t, "r")) == NULL)
{
warnNoFL(eMsg1("file '%s' can't be opened", t));
return;
}
for (;;)
{
if (fgets(one_fn, 128 - 1, fl) == NULL)
break;
fnl = strlen(one_fn);
require(fnl<=left, "no more room in File List Area");
/* drop the trailing LF */
if (one_fn[fnl - 1] == 0x0a) one_fn[fnl - 1] = ' ';
strcat(Fn_in_Fl, one_fn);
left = left - fnl;
require(NumFiles<MaxNumFiles,"exceeded max # of input files");
FileStr[NumFiles++] = flp;
flp = flp + fnl;
}
fclose(fl);
for (i=0;i < MaxFLArea;i++) if (Fn_in_Fl[i] == ' ') Fn_in_Fl[i] = '\0';
DontAcceptStdin = 1;
}
static void
#ifdef __USE_PROTOS
pLLK( char *s, char *t )
#else
pLLK( s, t )
char *s;
char *t;
#endif
{
LL_k = atoi(t);
if ( LL_k <= 0 ) {
warnNoFL("must have at least one token of lookahead (setting to 1)");
LL_k = 1;
}
}
static void
#ifdef __USE_PROTOS
pCk( char *s, char *t )
#else
pCk( s, t )
char *s;
char *t;
#endif
{
CLL_k = atoi(t);
if ( CLL_k <= 0 ) {
warnNoFL("must have at least one token of look-ahead (setting to 1)");
CLL_k = 1;
}
}
static void /* MR6 */
#ifdef __USE_PROTOS
pTab( char *s, char *t ) /* MR6 */
#else
pTab( s, t ) /* MR6 */
char *s; /* MR6 */
char *t; /* MR6 */
#endif
{ /* MR6 */
TabWidth = atoi(t); /* MR6 */
if ( TabWidth < 0 || TabWidth > 8 ) { /* MR6 */
warnNoFL("tab width must be between 1 and 8"); /* MR6 */
TabWidth=0; /* MR6 */
} /* MR6 */
} /* MR6 */
static int ambAidDepthSpecified=0; /* MR11 */
static void /* MR11 */
#ifdef __USE_PROTOS
pAAd( char *s, char *t ) /* MR11 */
#else
pAAd( s, t ) /* MR11 */
char *s; /* MR11 */
char *t; /* MR11 */
#endif
{ /* MR11 */
ambAidDepthSpecified=1; /* MR11 */
MR_AmbAidDepth = atoi(t); /* MR11 */
} /* MR11 */
static void /* MR11 */
#ifdef __USE_PROTOS
pTreport( char *s, char *t ) /* MR11 */
#else
pTreport( s, t ) /* MR11 */
char *s; /* MR11 */
char *t; /* MR11 */
#endif
{ /* MR11 */
TnodesReportThreshold = atoi(t); /* MR11 */
} /* MR11 */
#ifdef __USE_PROTOS
void chkGTFlag(void) /* 7-Apr-97 MR1 */
#else
void chkGTFlag() /* 7-Apr-97 MR1 */
#endif
{
if ( !GenAST )
warn("#-variable or other AST item referenced w/o -gt option");
}
#ifdef __USE_PROTOS
static void pInfo(char *s, char *t) /* MR10 */
#else
static void pInfo(s,t) /* MR10 */
char *s;
char *t;
#endif
{
char *p;
int q;
for (p=t; *p != 0; p++) {
q=tolower(*p);
if (q=='t') {
InfoT=1;
} else if (q=='p') {
InfoP=1;
} else if (q=='m') {
InfoM=1;
} else if (q=='o') {
InfoO=1;
} else if (q=='0') {
; /* nothing */
} else if (q=='f') {
InfoF=1;
} else {
warnNoFL(eMsgd("unrecognized -info option \"%c\"",(int)*p));
};
};
}
#ifdef __USE_PROTOS
static void pCGen(void) { CodeGen = FALSE; LexGen = FALSE; }
static void pLGen(void) { LexGen = FALSE; }
static void pXTGen(void){ MR_Inhibit_Tokens_h_Gen = TRUE; }
static void pTGen(void) { TraceGen = TRUE; }
static void pSGen(void) { GenExprSetsOpt = FALSE; }
static void pPrt(void) { PrintOut = TRUE; pCGen(); pLGen(); }
static void pPrtA(void) { PrintOut = TRUE; PrintAnnotate = TRUE; pCGen(); pLGen(); }
static void pAst(void) { GenAST = TRUE; }
static void pANSI(void) { GenANSI = TRUE; }
static void pCr(void) { GenCR = TRUE; }
static void pNOPURIFY(void) { PURIFY = FALSE; }
/*static void pCt(void) { warnNoFL("-ct option is now the default"); }*/
static void pLI(void) { GenLineInfo = TRUE; GenLineInfoMS = FALSE; } /* MR14 */
static void pLIms(void) { GenLineInfo = TRUE; GenLineInfoMS = TRUE; } /* MR14 */
static void pFr(char *s, char *t) {RemapFileName = t;}
static void pFe(char *s, char *t) {ErrFileName = t;}
static void pFl(char *s, char *t) {DlgFileName = t;}
static void pFm(char *s, char *t) {ModeFileName = t;}
static void pFt(char *s, char *t) {DefFileName = t;}
static void pE1(void) { elevel = 1; }
static void pE2(void) { elevel = 2; }
static void pE3(void) { elevel = 3; }
static void pEGen(void) { GenEClasseForRules = 1; }
static void pDL(void)
{
DemandLookahead = 1;
if ( GenCC ) {
warnNoFL("-gk does not work currently in C++ mode; -gk turned off");
DemandLookahead = 0;
}
}
static void pAA(char *s,char *t) {MR_AmbAidRule = t;} /* MR11 */
static void pAAm(char *s){MR_AmbAidMultiple = 1;} /* MR11 */
static void pGHdr(void) { GenStdPccts = 1; }
static void pFHdr(char *s, char *t) { stdpccts = t; pGHdr(); }
static void pW1(void) { WarningLevel = 1; }
static void pNewAST(void) { NewAST = 1; } /* MR13 */
static void ptmakeInParser(void) { tmakeInParser = 1; } /* MR23 */
static void pAlpha(void) { AlphaBetaTrace = 1; } /* MR14 */
static void pMR_BlkErr(void) { MR_BlkErr = 1; } /* MR21 */
static void pStdout(void) {UseStdout = 1; } /* MR6 */
static void pW2(void) { WarningLevel = 2; }
static void pCC(void) { GenCC = TRUE; }
#else
static void pCGen() { CodeGen = FALSE; LexGen = FALSE; }
static void pLGen() { LexGen = FALSE; }
static void pXTGen(){ MR_Inhibit_Tokens_h_Gen = TRUE; } /* MR14 */
static void pTGen() { TraceGen = TRUE; }
static void pSGen() { GenExprSetsOpt = FALSE; }
static void pPrt() { PrintOut = TRUE; pCGen(); pLGen(); }
static void pPrtA() { PrintOut = TRUE; PrintAnnotate = TRUE; pCGen(); pLGen(); }
static void pAst() { GenAST = TRUE; }
static void pANSI() { GenANSI = TRUE; }
static void pCr() { GenCR = TRUE; }
static void pNOPURIFY() { PURIFY = FALSE; }
/*static void pCt() { warnNoFL("-ct option is now the default"); }*/
static void pLI() { GenLineInfo = TRUE; GenLineInfoMS = FALSE; } /* MR14 */
static void pLIms() { GenLineInfo = TRUE; GenLineInfoMS = TRUE; } /* MR14 */
static void pFr(s,t) char *s, *t; {RemapFileName = t;}
static void pFe(s,t) char *s, *t; {ErrFileName = t;}
static void pFl(s,t) char *s, *t; {DlgFileName = t;}
static void pFm(s,t) char *s, *t; {ModeFileName = t;}
static void pFt(s,t) char *s, *t; {DefFileName = t;}
static void pE1() { elevel = 1; }
static void pE2() { elevel = 2; }
static void pE3() { elevel = 3; }
static void pEGen() { GenEClasseForRules = 1; }
static void pDL()
{
DemandLookahead = 1;
if ( GenCC ) {
warnNoFL("-gk does not work currently in C++ mode; -gk turned off");
DemandLookahead = 0;
}
}
static void pAA(s,t) char *s; char *t; {MR_AmbAidRule = t;} /* MR11 BJS 20-Mar-98 */
static void pAAm(s) char *s; {MR_AmbAidMultiple = 1;} /* MR11 BJS 20-Mar-98 */
static void pGHdr() { GenStdPccts = 1; }
static void pFHdr(s,t) char *s, *t; { stdpccts = t; pGHdr(); }
static void pW1() { WarningLevel = 1; }
static void pNewAST() { NewAST = 1; } /* MR13 */
static void ptmakeInParser() { tmakeInParser = 1; } /* MR23 */
static void pAlpha() { AlphaBetaTrace = 1; } /* MR14 */
static void pMR_BlkErr() { MR_BlkErr = 1; } /* MR21 */
static void pStdout() {UseStdout = 1; } /* MR6 */
static void pW2() { WarningLevel = 2; }
static void pCC() { GenCC = TRUE; }
#endif
static void
#ifdef __USE_PROTOS
pPre( char *s, char *t )
#else
pPre( s, t )
char *s;
char *t;
#endif
{
RulePrefix = t;
}
static void
#ifdef __USE_PROTOS
pOut( char *s, char *t )
#else
pOut( s, t )
char *s;
char *t;
#endif
{
OutputDirectory = t;
}
static void
#ifdef __USE_PROTOS
pPred( void )
#else
pPred( )
#endif
{
warnNoFL("-pr is no longer used (predicates employed if present); see -prc, -mrhoist, -mrhoistk");
/*
** if ( DemandLookahead )
** warnNoFL("-gk conflicts with -pr; -gk turned off");
** DemandLookahead = 0;
** HoistPredicateContext = 0;
*/
}
static void
#ifdef __USE_PROTOS
pPredCtx( char *s, char *t )
#else
pPredCtx(s,t)
char *s;
char *t;
#endif
{
if ( ci_strequ(t,"on")) HoistPredicateContext = 1;
else if ( ci_strequ(t,"off")) HoistPredicateContext = 0;
if ( DemandLookahead )
{
warnNoFL("-gk incompatible with semantic predicate usage; -gk turned off");
DemandLookahead = 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?