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

📄 lex.c

📁 本工具提供一个词法分析器和语法分析器的集成开发环境
💻 C
📖 第 1 页 / 共 2 页
字号:
#elseGenASTSymbolRedefs( f )FILE *f;#endif{	char **p;	fprintf(f, "\n/* rename PCCTS-supplied AST symbols to be 'ParserName_symbol' */\n");	for (p = &ASTSymbols[0]; *p!=NULL; p++)	{		fprintf(f, "#define %s %s_%s\n", *p, ParserName, *p);	}}/* redefine all sets generated by ANTLR; WARNING:  'zzerr', 'setwd' must match * use in bits.c (DumpSetWd() etc...) */void#ifdef __USE_PROTOSGenSetRedefs( FILE *f )#elseGenSetRedefs( f )FILE *f;#endif{	int i;	for (i=1; i<=wordnum; i++)	{		fprintf(f, "#define setwd%d %s_setwd%d\n", i, ParserName, i);	}	for (i=1; i<=esetnum; i++)	{		fprintf(f, "#define zzerr%d %s_err%d\n", i, ParserName, i);	}}/* Find all return types/parameters that require structs and def * all rules with ret types. */void#ifdef __USE_PROTOSGenRulePrototypes( FILE *f, Junction *p )#elseGenRulePrototypes( f, p )FILE *f;Junction *p;#endif{	int i;	i = 1;	while ( p!=NULL )	{		if ( p->ret != NULL )		{			if ( HasComma(p->ret) )			{				DumpRetValStruct(f, p->ret, i);			}			fprintf(f, "\n#ifdef __USE_PROTOS\n");			if ( HasComma(p->ret) )			{				fprintf(f, "extern struct _rv%d", i);			}			else			{				fprintf(f, "extern ");				DumpType(p->ret, f);			}			fprintf(f, " %s%s(", RulePrefix, p->rname);			DumpANSIFunctionArgDef(f,p);			fprintf(f, ";\n");#ifdef OLD			if ( p->pdecl != NULL || GenAST )			{				if ( GenAST ) {					fprintf(f, "AST **%s",(p->pdecl!=NULL)?",":"");				}				if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);			}			else fprintf(f, "void");			fprintf(f, ");\n");#endif			fprintf(f, "#else\n");			if ( HasComma(p->ret) )			{				fprintf(f, "extern struct _rv%d", i);			}			else			{				fprintf(f, "extern ");				DumpType(p->ret, f);			}			fprintf(f, " %s%s();\n", RulePrefix, p->rname);			fprintf(f, "#endif\n");		}		else		{			fprintf(f, "\n#ifdef __USE_PROTOS\n");			fprintf(f, "void %s%s(", RulePrefix, p->rname);			DumpANSIFunctionArgDef(f,p);			fprintf(f, ";\n");#ifdef OLD			if ( p->pdecl != NULL || GenAST )			{				if ( GenAST ) {					fprintf(f, "AST **%s",(p->pdecl!=NULL)?",":"");				}				if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);			}			else fprintf(f, "void");			fprintf(f, ");\n");#endif			fprintf(f, "#else\n");			fprintf(f, "extern void %s%s();\n", RulePrefix, p->rname);			fprintf(f, "#endif\n");		}		i++;		p = (Junction *)p->p2;	}}/* Define all rules in the class.h file; generate any required * struct definitions first, however. */void#ifdef __USE_PROTOSGenRuleMemberDeclarationsForCC( FILE *f, Junction *q )#elseGenRuleMemberDeclarationsForCC( f, q )FILE *f;Junction *q;#endif{	Junction *p = q;	int i;	fprintf(f, "private:\n");	/* Dump dflt handler declaration */	fprintf(f, "\tvoid zzdflthandlers( int _signal, int *_retsignal );\n\n");	fprintf(f, "public:\n");	/* Dump return value structs */	i = 1;	while ( p!=NULL )	{		if ( p->ret != NULL )		{			if ( HasComma(p->ret) )			{				DumpRetValStruct(f, p->ret, i);			}		}		i++;		p = (Junction *)p->p2;	}	/* Dump member func defs && CONSTRUCTOR */	fprintf(f, "\t%s(ANTLRTokenBuffer *input);\n", CurrentClassName);/*	fprintf(f, "\t%s(ANTLRTokenBuffer *input, ANTLRTokenType eof);\n",			   CurrentClassName);*/	i = 1;	p = q;	while ( p!=NULL )	{		if ( p->ret != NULL )		{			if ( HasComma(p->ret) )			{				fprintf(f, "\tstruct _rv%d", i);			}			else			{				fprintf(f, "\t");				DumpType(p->ret, f);			}			fprintf(f, " %s%s(",RulePrefix,p->rname);			DumpANSIFunctionArgDef(f,p);			fprintf(f, ";\n");#ifdef OLD			if ( p->pdecl != NULL || GenAST )			{				if ( GenAST ) fprintf(f, "ASTBase **%s",(p->pdecl!=NULL)?",":"");				if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);			}			fprintf(f, ");\n");#endif		}		else		{			fprintf(f, "\tvoid %s%s(",RulePrefix,p->rname);			DumpANSIFunctionArgDef(f,p);			fprintf(f, ";\n");#ifdef OLD			if ( p->pdecl != NULL || GenAST )			{				if ( GenAST ) fprintf(f, "ASTBase **%s",(p->pdecl!=NULL)?",":"");				if ( p->pdecl!=NULL ) fprintf(f, "%s", p->pdecl);			}			fprintf(f, ");\n");#endif		}		i++;		p = (Junction *)p->p2;	}}/* Given a list of ANSI-style parameter declarations, print out a * comma-separated list of the symbols (w/o types). * Basically, we look for a comma, then work backwards until start of * the symbol name.  Then print it out until 1st non-alnum char.  Now, * move on to next parameter. * *//* MR5 	Jan Mikkelsen 26-May-97 - added initalComma parameter              */void#ifdef __USE_PROTOSDumpListOfParmNames( char *pdecl, FILE *output, int initialComma )  /* MR5 */#elseDumpListOfParmNames( pdecl, output, initialComma )		    /* MR5 */char *pdecl;	             		 			  	    /* MR5 */FILE *output;							                            /* MR5 */int initialComma;			                                        /* MR5 */#endif{	int firstTime = 1, done = 0;	require(output!=NULL, "DumpListOfParmNames: NULL parm");	if ( pdecl == NULL ) return;	while ( !done )	{		if ( !firstTime || initialComma ) putc(',', output);        /* MR5 */		done = DumpNextNameInDef(&pdecl, output);		firstTime = 0;	}}/* given a list of parameters or return values, dump the next * name to output.  Return 1 if last one just printed, 0 if more to go. */int#ifdef __USE_PROTOSDumpNextNameInDef( char **q, FILE *output )#elseDumpNextNameInDef( q, output )char **q;FILE *output;#endif{	char *p = *q;		/* where did we leave off? */	int done=0;	while ( *p!='\0' && *p!=',' ) p++;		/* find end of decl */	if ( *p == '\0' ) done = 1;	while ( !isalnum(*p) && *p!='_' ) --p;	/* scan back until valid var character */	while ( isalnum(*p) || *p=='_' ) --p;	/* scan back until beginning of variable */	p++;						/* move to start of variable */	while ( isalnum(*p) || *p=='_'  ) {putc(*p, output); p++;}	while ( *p!='\0' && *p!=',' ) p++;		/* find end of decl */	p++;				/* move past this parameter */	*q = p;				/* record where we left off */	return done;}/* Given a list of ANSI-style parameter declarations, dump K&R-style * declarations, one per line for each parameter.  Basically, convert * comma to semi-colon, newline. */void#ifdef __USE_PROTOSDumpOldStyleParms( char *pdecl, FILE *output )#elseDumpOldStyleParms( pdecl, output )char *pdecl;FILE *output;#endif{	require(output!=NULL, "DumpOldStyleParms: NULL parm");	if ( pdecl == NULL ) return;	while ( *pdecl != '\0' )	{		if ( *pdecl == ',' )		{			pdecl++;			putc(';', output); putc('\n', output);			while ( *pdecl==' ' || *pdecl=='\t' || *pdecl=='\n' ) pdecl++;		}		else {putc(*pdecl, output); pdecl++;}	}	putc(';', output);	putc('\n', output);}/* Take in a type definition (type + symbol) and print out type only */void#ifdef __USE_PROTOSDumpType( char *s, FILE *f )#elseDumpType( s, f )char *s;FILE *f;#endif{	char *p, *end;	require(s!=NULL, "DumpType: invalid type string");	p = &s[strlen(s)-1];		/* start at end of string and work back *//* MR11 */	/* scan back until valid variable character */	while ( !isalnum(*p) && *p!='_' ) --p;	/* scan back until beginning of variable */	while ( isalnum(*p) || *p=='_' ) --p;	if ( p<=s )	{		warnNoFL(eMsg1("invalid parameter/return value: '%s'",s));		return;	}	end = p;					/* here is where we stop printing alnum */	p = s;	while ( p!=end ) {putc(*p, f); p++;} /* dump until just before variable */	while ( *p!='\0' )					 /* dump rest w/o variable */	{		if ( !isalnum(*p) && *p!='_' ) putc(*p, f);		p++;	}}/* check to see if string e is a word in string s */int#ifdef __USE_PROTOSstrmember( char *s, char *e )#elsestrmember( s, e )char *s;char *e;#endif{    register char *p;    require(s!=NULL&&e!=NULL, "strmember: NULL string");    if ( *e=='\0' ) return 1;   /* empty string is always member */    do {	while ( *s!='\0' && !isalnum(*s) && *s!='_' )	++s;	p = e;	while ( *p!='\0' && *p==*s ) {p++; s++;}	if ( *p=='\0' ) {	    if ( *s=='\0' ) return 1;	    if ( !isalnum (*s) && *s != '_' ) return 1;	}	while ( isalnum(*s) || *s == '_' )	++s;    } while ( *s!='\0' );    return 0;}int#ifdef __USE_PROTOSHasComma( char *s )#elseHasComma( s )char *s;#endif{	while (*s!='\0')		if ( *s++ == ',' ) return 1;	return 0;}void#ifdef __USE_PROTOSDumpRetValStruct( FILE *f, char *ret, int i )#elseDumpRetValStruct( f, ret, i )FILE *f;char *ret;int i;#endif{	fprintf(f, "\nstruct _rv%d {\n", i);	while ( *ret != '\0' )	{		 while ( *ret==' ' || *ret=='\t' ) ret++; /* ignore white */		 putc('\t', f);		 while ( *ret!=',' && *ret!='\0' ) {putc(*ret,f); ret++;}		 if ( *ret == ',' ) {putc(';', f); putc('\n', f); ret++;}	}	fprintf(f, ";\n};\n");}/* given "s" yield s -- DESTRUCTIVE (we modify s if starts with " else return s) */char *#ifdef __USE_PROTOSStripQuotes( char *s )#elseStripQuotes( s )char *s;#endif{	if ( *s == '"' )	{		s[ strlen(s)-1 ] = '\0';    /* remove last quote */		return( s+1 );				/* return address past initial quote */	}	return( s );}

⌨️ 快捷键说明

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