⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 本工具提供一个词法分析器和语法分析器的集成开发环境
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * 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-1998 */#include <stdio.h>#ifdef __cplusplus#ifndef __STDC__#define __STDC__#endif#endif#include "stdpccts.h"#define MAX_INT_STACK 50static 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 __STDC__extern void ProcessArgs(int, char **, Opt *);#elseextern void ProcessArgs();#endif#ifdef __STDC__int ci_strequ(char *a,char *b)#elseint 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 __STDC__pStdin( void )#elsepStdin( )#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 __STDC__pFile( char *s )#elsepFile( 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 __STDC__pFileList( char *s, char *t )#elsepFileList( 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 __STDC__pLLK( char *s, char *t )#elsepLLK( 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 __STDC__pCk( char *s, char *t )#elsepCk( 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 __STDC__pTab( char *s, char *t )			                        	     /* MR6 */#elsepTab( 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 __STDC__pAAd( char *s, char *t )			                        	     /* MR11 */#elsepAAd( s, t )				                    		             /* MR11 */char *s;							                                 /* MR11 */char *t;							                                 /* MR11 */#endif{								                                     /* MR11 */    ambAidDepthSpecified=1;                                          /* MR11 */	MR_AmbAidDepth = atoi(t);				                         /* MR11 */}							                                         /* MR11 */static void						                                     /* MR11 */#ifdef __STDC__pTreport( char *s, char *t )			                       	     /* MR11 */#elsepTreport( s, t )				                  		             /* MR11 */    char *s;							                             /* MR11 */    char *t;							                             /* MR11 */#endif{								                                     /* MR11 */	TnodesReportThreshold = atoi(t);				                 /* MR11 */}							                                         /* MR11 */#ifdef __STDC__void chkGTFlag(void)	                                    /* 7-Apr-97 MR1 */#elsevoid chkGTFlag()                                            /* 7-Apr-97 MR1 */#endif{	if ( !GenAST )		warn("#-variable or other AST item referenced w/o -gt option");}#ifdef __STDC__static void pInfo(char *s, char *t)                         /* MR10 */#elsestatic 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 __STDC__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 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 pAlpha(void) { AlphaBetaTrace = 1; }                    /* MR14 */static void pStdout(void) {UseStdout = 1; }		                    /* MR6 */static void pW2(void) { WarningLevel = 2; }static void pCC(void) { GenCC = TRUE; }#elsestatic 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 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 pAlpha() { AlphaBetaTrace = 1; }                         /* MR14 */static void pStdout() {UseStdout = 1; }	                             /* MR6 */static void pW2() { WarningLevel = 2; }static void pCC() { GenCC = TRUE; }#endifstatic void#ifdef __STDC__pPre( char *s, char *t )#elsepPre( s, t )char *s;char *t;#endif{	RulePrefix = t;}static void#ifdef __STDC__pOut( char *s, char *t )#elsepOut( s, t )char *s;char *t;#endif{	OutputDirectory = t;}static void#ifdef __STDC__pPred( void )#elsepPred( )#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 __STDC__pPredCtx( char *s, char *t )#elsepPredCtx(s,t)char *s;char *t;#endif{	if ( ci_strequ(t,"on")) HoistPredicateContext = 1;	else if ( ci_strequ(t,"off")) HoistPredicateContext = 0;	if ( DemandLookahead )	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -