📄 lex.c
字号:
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_PROTOS
GenSetRedefs( FILE *f )
#else
GenSetRedefs( 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.
*
* This is for the declaration, not the definition.
*/
void
#ifdef __USE_PROTOS
GenRulePrototypes( FILE *f, Junction *p )
#else
GenRulePrototypes( f, p )
FILE *f;
Junction *p;
#endif
{
int i;
i = 1;
while ( p!=NULL )
{
if ( p->ret != NULL )
{
/* MR23 */ if ( hasMultipleOperands(p->ret) )
{
DumpRetValStruct(f, p->ret, i);
}
fprintf(f, "\n#ifdef __USE_PROTOS\n");
/* MR23 */ if ( hasMultipleOperands(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,1 /* emit initializers ? */);
fprintf(f, ";\n");
fprintf(f, "#else\n");
/* MR23 */ if ( hasMultipleOperands(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, 1 /* emit initializers ? */ );
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_PROTOS
GenRuleMemberDeclarationsForCC( FILE *f, Junction *q )
#else
GenRuleMemberDeclarationsForCC( 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 )
{
/* MR23 */ if ( hasMultipleOperands(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 )
{
/* MR23 */ if ( hasMultipleOperands(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, 1 /* emit initializers ? */ );
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, 1 /* emit initializers ? */);
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_PROTOS
DumpListOfParmNames(char *pdecl, FILE *output, int initialComma) /* MR5 */
#else
DumpListOfParmNames(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.
*/
/* MR23 Total rewrite */
int
#ifdef __USE_PROTOS
DumpNextNameInDef( char **q, FILE *output )
#else
DumpNextNameInDef( q, output )
char **q;
FILE *output;
#endif
{
char *p;
char *t;
char *pDataType;
char *pSymbol;
char *pEqualSign;
char *pValue;
char *pSeparator;
int nest = 0;
p = endFormal(*q,
&pDataType,
&pSymbol,
&pEqualSign,
&pValue,
&pSeparator,
&nest);
/* MR26 Handle rule arguments such as: IIR_Bool (IIR_Decl::*contstraint)()
For this we need to strip off anything which follows the symbol.
*/
/* MR26 */ t = pSymbol;
/* MR26 */ if (t != NULL) {
/* MR26 */ for (t = pSymbol; *t != 0; t++) {
/* MR26 */ if (! (isalpha(*t) || isdigit(*t) || *t == '_' || *t == '$')) break;
/* MR26 */ }
/* MR26 */ }
/* MR26 */ fprintf(output,strBetween(pSymbol, t, pSeparator));
*q = p;
return (*pSeparator == 0);
}
/* 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_PROTOS
DumpOldStyleParms( char *pdecl, FILE *output )
#else
DumpOldStyleParms( 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 */
/* MR23 Total rewrite */
void
#ifdef __USE_PROTOS
DumpType( char *s, FILE *f )
#else
DumpType( s, f )
char *s;
FILE *f;
#endif
{
char *p;
char *pDataType;
char *pSymbol;
char *pEqualSign;
char *pValue;
char *pSeparator;
int nest = 0;
require(s!=NULL, "DumpType: invalid type string");
p = endFormal(s,
&pDataType,
&pSymbol,
&pEqualSign,
&pValue,
&pSeparator,
&nest);
fprintf(f,strBetween(pDataType, pSymbol, pSeparator));
}
/* check to see if string e is a word in string s */
int
#ifdef __USE_PROTOS
strmember( char *s, char *e )
#else
strmember( 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;
}
#if 0
/* MR23 Replaced by hasMultipleOperands() */
int
#ifdef __USE_PROTOS
HasComma( char *s )
#else
HasComma( s )
char *s;
#endif
{
while (*s!='\0')
if ( *s++ == ',' ) return 1;
return 0;
}
#endif
/* MR23 Total rewrite */
void
#ifdef __USE_PROTOS
DumpRetValStruct( FILE *f, char *ret, int i )
#else
DumpRetValStruct( f, ret, i )
FILE *f;
char *ret;
int i;
#endif
{
char *p = ret;
char *pDataType;
char *pSymbol;
char *pEqualSign;
char *pValue;
char *pSeparator;
int nest = 0;
fprintf(f, "\nstruct _rv%d {\n", i);
while (*p != 0 && nest == 0) {
p = endFormal(p,
&pDataType,
&pSymbol,
&pEqualSign,
&pValue,
&pSeparator,
&nest);
fprintf(f,"\t");
fprintf(f,strBetween(pDataType, pSymbol, pSeparator));
fprintf(f," ");
fprintf(f,strBetween(pSymbol, pEqualSign, pSeparator));
fprintf(f,";\n");
}
fprintf(f,"};\n");
}
/* given "s" yield s -- DESTRUCTIVE (we modify s if starts with " else return s) */
char *
#ifdef __USE_PROTOS
StripQuotes( char *s )
#else
StripQuotes( 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 + -