main.c
来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 1,748 行 · 第 1/4 页
C
1,748 行
MR_orphanRules(stderr);
if (LTinTokenAction && WarningLevel >= 2) {
if (GenCC) {
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.");
}
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.");
}
if ( PrintOut )
{
if ( SynDiag == NULL ) {warnNoFL("no grammar description recognized");}
else PRINT(SynDiag);
}
#ifdef DBG_LL1
#endif
GenRemapFile(); /* create remap.h */
/* MR10 */ if (FoundGuessBlk) {
#ifdef __cplusplus__
/* MR10 */ list_apply(NumericPredLabels, (void (*)(void *))report_numericPredLabels);
#else
#ifdef __USE_PROTOS
/* MR10 */ list_apply(NumericPredLabels, (void (*)(void *))report_numericPredLabels);
#else
/* MR10 */ list_apply(NumericPredLabels,report_numericPredLabels);
#endif
#endif
/* MR10 */ };
if (InfoT && TnodesAllocated > 0) {
if (TnodesPeak > 10000) {
fprintf(stdout,"\nTree Nodes: peak %dk created %dk lost %d\n",
(TnodesPeak/1000),
(TnodesAllocated/1000),
TnodesInUse-tnodes_used_in_guard_predicates_etc);
} else {
fprintf(stdout,"\nTree Nodes: peak %d created %d lost %d\n",
TnodesPeak,
TnodesAllocated,
TnodesInUse-tnodes_used_in_guard_predicates_etc);
};
};
if (InfoF) {
DumpFcache();
};
if (MR_skipped_e3_report) {
fprintf(stderr,"note: use -e3 to get exact information on ambiguous tuples\n");
};
if (MR_BadExprSets != 0) {
fprintf(stderr,"note: Unreachable C or C++ code was generated for empty expression sets,\n");
fprintf(stderr," probably due to undefined rules or infinite left recursion.\n");
fprintf(stderr," To locate: search the generated code for \"empty set expression\"\n");
};
if (MR_AmbAidRule != NULL && MR_matched_AmbAidRule==0) {
RuleEntry *q = (RuleEntry *) hash_get(Rname,MR_AmbAidRule);
if (MR_AmbAidLine == 0 && q == NULL) {
warnNoFL(eMsg2("there is no rule \"%s\" so \"-aa %s\" will never match",
MR_AmbAidRule,MR_AmbAidRule));
} else {
warnNoFL(eMsg1("there was no ambiguity that matched \"-aa %s\"",MR_AmbAidRule));
};
};
if (AlphaBetaTrace) {
if (MR_AlphaBetaMessageCount == 0) {
fprintf(stderr,"note: there were no messages about \"(alpha)? beta\" blocks added to the generated code\n");
} else {
fprintf(stderr,"note: there were %d messages about \"(alpha)? beta\" blocks added to the generated code\n",
MR_AlphaBetaMessageCount);
}
if (set_null(MR_CompromisedRules)) {
fprintf(stderr,"note: the list of rules with compromised follow sets is empty\n");
} else {
fprintf(stderr,"note: the following is a list of rules which *may* have incorrect\n");
fprintf(stderr," follow sets computed as a result of an \"(alpha)? beta\" block\n");
fprintf(stderr,"\n");
MR_dumpRuleSet(MR_CompromisedRules);
fprintf(stderr,"\n");
}
}
cleanUp();
exit(PCCTS_EXIT_SUCCESS);
return 0; /* MR11 make compilers happy */
}
static void
#ifdef __USE_PROTOS
init( void )
#else
init( )
#endif
{
SignalEntry *q;
Tname = newHashTable();
Rname = newHashTable();
Fcache = newHashTable();
Tcache = newHashTable();
Sname = newHashTable();
Pname = newHashTable(); /* MR11 */
/* Add default signal names */
q = (SignalEntry *)hash_add(Sname,
"NoViableAlt",
(Entry *)newSignalEntry("NoViableAlt"));
require(q!=NULL, "cannot alloc signal entry");
q->signum = sigNoViableAlt;
q = (SignalEntry *)hash_add(Sname,
"MismatchedToken",
(Entry *)newSignalEntry("MismatchedToken"));
require(q!=NULL, "cannot alloc signal entry");
q->signum = sigMismatchedToken;
q = (SignalEntry *)hash_add(Sname,
"NoSemViableAlt",
(Entry *)newSignalEntry("NoSemViableAlt"));
require(q!=NULL, "cannot alloc signal entry");
q->signum = sigNoSemViableAlt;
reserved_positions = empty;
all_tokens = empty;
imag_tokens = empty;
tokclasses = empty;
TokenStr = (char **) calloc(TSChunk, sizeof(char *));
require(TokenStr!=NULL, "main: cannot allocate TokenStr");
FoStack = (int **) calloc(CLL_k+1, sizeof(int *));
require(FoStack!=NULL, "main: cannot allocate FoStack");
FoTOS = (int **) calloc(CLL_k+1, sizeof(int *));
require(FoTOS!=NULL, "main: cannot allocate FoTOS");
Cycles = (ListNode **) calloc(CLL_k+1, sizeof(ListNode *));
require(Cycles!=NULL, "main: cannot allocate Cycles List");
MR_CompromisedRules=empty; /* MR14 */
}
static void
#ifdef __USE_PROTOS
help( void )
#else
help( )
#endif
{
Opt *p = options;
fprintf(stderr, "antlr [options] f1 f2 ... fn\n");
while ( *(p->option) != '*' )
{
fprintf(stderr, " %-9s%s %s\n",
p->option,
(p->arg)?"___":" ",
p->descr);
p++;
}
}
/* The RulePtr array is filled in here. RulePtr exists primarily
* so that sets of rules can be maintained for the FOLLOW caching
* mechanism found in rJunc(). RulePtr maps a rule num from 1 to n
* to a pointer to its RuleBlk junction where n is the number of rules.
*/
static void
#ifdef __USE_PROTOS
buildRulePtr( void )
#else
buildRulePtr( )
#endif
{
int r=1;
Junction *p = SynDiag;
RulePtr = (Junction **) calloc(NumRules+1, sizeof(Junction *));
require(RulePtr!=NULL, "cannot allocate RulePtr array");
while ( p!=NULL )
{
require(r<=NumRules, "too many rules???");
RulePtr[r++] = p;
p = (Junction *)p->p2;
}
}
void
#ifdef __USE_PROTOS
dlgerror(const char *s)
#else
dlgerror(s)
char *s;
#endif
{
fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);
fprintf(stderr, " lexical error: %s (text was '%s')\n",
((s == NULL) ? "Lexical error" : s), zzlextext);
}
void
#ifdef __USE_PROTOS
readDescr( void )
#else
readDescr( )
#endif
{
zzerr = dlgerror;
input = NextFile();
if ( input==NULL ) fatal("No grammar description found (exiting...)");
ANTLR(grammar(), input);
tnodes_used_in_guard_predicates_etc=TnodesInUse; /* MR10 */
}
FILE *
#ifdef __USE_PROTOS
NextFile( void )
#else
NextFile( )
#endif
{
FILE *f;
for (;;)
{
CurFile++;
if ( CurFile >= NumFiles ) return(NULL);
if ( ci_strequ(FileStr[CurFile],"stdin")) return stdin;
f = fopen(FileStr[CurFile], "r");
if ( f == NULL )
{
warnNoFL( eMsg1("file %s doesn't exist; ignored", FileStr[CurFile]) );
}
else
{
return(f);
}
}
}
/*
* Return a string corresponding to the output file name associated
* with the input file name passed in.
*
* Observe the following rules:
*
* f.e --> f".c"
* f --> f".c"
* f. --> f".c"
* f.e.g --> f.e".c"
*
* Where f,e,g are arbitrarily long sequences of characters in a file
* name.
*
* In other words, if a ".x" appears on the end of a file name, make it
* ".c". If no ".x" appears, append ".c" to the end of the file name.
*
* C++ mode using .cpp not .c.
*
* Use malloc() for new string.
*/
char *
#ifdef __USE_PROTOS
outname( char *fs )
#else
outname( fs )
char *fs;
#endif
{
if ( GenCC) {
return outnameX(fs,CPP_FILE_SUFFIX);
} else {
return outnameX(fs,".c");
};
}
char *
#ifdef __USE_PROTOS
outnameX( char *fs ,char *suffix)
#else
outnameX( fs , suffix )
char *fs;
char *suffix;
#endif
{
static char buf[MaxFileName+1];
char *p;
require(fs!=NULL&&*fs!='\0', "outname: NULL filename");
p = buf;
strcpy(buf, fs);
while ( *p != '\0' ) {p++;} /* Stop on '\0' */
while ( *p != '.' && p != buf ) {--p;} /* Find '.' */
if ( p != buf ) *p = '\0'; /* Found '.' */
require(strlen(buf) + 2 < (size_t)MaxFileName, "outname: filename too big");
strcat(buf,suffix);
return( buf );
}
void
#ifdef __USE_PROTOS
fatalFL( char *err_, char *f, int l )
#else
fatalFL( err_, f, l )
char *err_;
char *f;
int l;
#endif
{
fprintf(stderr, ErrHdr, f, l);
fprintf(stderr, " %s\n", err_);
cleanUp();
exit(PCCTS_EXIT_FAILURE);
}
void
#ifdef __USE_PROTOS
fatal_intern( char *err_, char *f, int l )
#else
fatal_intern( err_, f, l )
char *err_;
char *f;
int l;
#endif
{
fprintf(stderr, ErrHdr, f, l);
fprintf(stderr, " #$%%*&@# internal error: %s\n", err_);
fprintf(stderr, ErrHdr, f, l);
fprintf(stderr, " [complain to nearest government official\n");
fprintf(stderr, ErrHdr, f, l);
fprintf(stderr, " or send hate-mail to parrt@parr-research.com;\n");
fprintf(stderr, ErrHdr, f, l);
fprintf(stderr, " please pray to the ``bug'' gods that there is a trival fix.]\n");
cleanUp();
exit(PCCTS_EXIT_FAILURE);
}
void
#ifdef __USE_PROTOS
cleanUp( void )
#else
cleanUp( )
#endif
{
if ( DefFile != NULL) fclose( DefFile );
}
/* sprintf up to 3 strings */
char *
#ifdef __USE_PROTOS
eMsg3( char *s, char *a1, char *a2, char *a3 )
#else
eMsg3( s, a1, a2, a3 )
char *s;
char *a1;
char *a2;
char *a3;
#endif
{
static char buf[250]; /* DANGEROUS as hell !!!!!! */
sprintf(buf, s, a1, a2, a3);
return( buf );
}
/* sprintf a decimal */
char *
#ifdef __USE_PROTOS
eMsgd( char *s, int d )
#else
eMsgd( s, d )
char *s;
int d;
#endif
{
static char buf[250]; /* DANGEROUS as hell !!!!!! */
sprintf(buf, s, d);
return( buf );
}
char *
#ifdef __USE_PROTOS
eMsgd2( char *s, int d1,int d2)
#else
eMsgd2( s, d1, d2 )
char *s;
int d1;
int d2;
#endif
{
static char buf[250]; /* DANGEROUS as hell !!!!!! */
sprintf(buf, s, d1, d2);
return( buf );
}
void
#ifdef __USE_PROTOS
s_fprT( FILE *f, set e )
#else
s_fprT( f, e )
FILE *f;
set e;
#endif
{
register unsigned *p;
unsigned *q;
if ( set_nil(e) ) return;
if ( (q=p=set_pdq(e)) == NULL ) fatal_internal("Can't alloc space for set_pdq");
fprintf(f, "{");
while ( *p != nil )
{
fprintf(f, " %s", TerminalString(*p));
p++;
}
fprintf(f, " }");
free((char *)q);
}
/* Return the token name or regular expression for a token number. */
char *
#ifdef __USE_PROTOS
TerminalString( int token )
#else
TerminalString( token )
int token;
#endif
{
int j;
static char imag_name[20];
/* look in all lexclasses for the token */
if ( TokenString(token) != NULL ) return TokenString(token);
for (j=0; j<NumLexClasses; j++)
{
lexmode(j);
if ( ExprString(token) != NULL ) return ExprString(token);
}
if (1) {
sprintf(imag_name,"UnknownToken#%d",token); /* MR13 */
return imag_name; /* MR13 */
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?