antlr.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/*
* A n t l r T r a n s l a t i o n H e a d e r
*
* Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
* Purdue University Electrical Engineering
* With AHPCRC, University of Minnesota
* ANTLR Version 1.33MR33
*
* ..\bin\antlr -gh antlr.g
*
*/
#define ANTLR_VERSION 13333
#include "pcctscfg.h"
#include "pccts_stdio.h"
#include "pcctscfg.h"
#include "set.h"
#include <ctype.h>
#include "syn.h"
#include "hash.h"
#include "generic.h"
#define zzSET_SIZE 20
#include "antlr.h"
#include "tokens.h"
#include "dlgdef.h"
#include "mode.h"
/* MR23 In order to remove calls to PURIFY use the antlr -nopurify option */
#ifndef PCCTS_PURIFY
#endif
/* MR20 G. Hobbelt For Borland C++ 4.x & 5.x compiling with ALL warnings enabled */
#if defined(__TURBOC__)
#endif
#ifdef __USE_PROTOS
static void chkToken(char *, char *, char *, int);
#else
static void chkToken();
#endif
#ifdef __USE_PROTOS
#else
static int isDLGmaxToken(); /* MR3 */
#endif
static int class_nest_level = 0;
/* MR20 G. Hobbelt extern definitions moved to antlr.h */
void
#ifdef __USE_PROTOS
grammar(void)
#else
grammar()
#endif
{
{
Graph g;
{
{
for (;;) {
}
else warn("additional #header statement ignored");
}
else {
if ( FirstAction==NULL ) {
} else {
warn("additional #first statement ignored");
};
}
else {
if ( GenCC ) {
warn("#parser meta-op incompatible with -CC; ignored");
}
else {
if ( RulePrefix[0]!='\0' )
{
warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored");
RulePrefix[0]='\0';
}
}
else warn("additional #parser statement ignored");
}
}
else {
{
char *fname;
else {
UserDefdTokens = 1;
}
}
}
else break; /* MR6 code for exiting loop "for sure" */
}
}
}
}
}
}
{
{
for (;;) {
{
}
}
else {
laction();
}
else {
lmember();
}
else {
lprefix();
}
else {
aLexclass();
}
else {
token();
}
else {
error();
}
else {
tclass();
}
else {
aPred();
}
else {
}
else {
class_def();
}
else {
zzmatch(98);
if ( class_nest_level==0 )
warn("missing class definition for trailing '}'");
}
else break; /* MR6 code for exiting loop "for sure" */
}
}
}
}
}
}
}
}
}
}
}
}
}
}
rule();
{
{
for (;;) {
rule();
/* MR21a */ /* Avoid use of a malformed graph when CannotContinue */
/* MR21a */ /* is already set */
/* MR21a */
/* MR21a */ }
/* MR21a */ }
}
else {
aLexclass();
}
else {
token();
}
else {
error();
}
else {
tclass();
}
else {
aPred();
}
else {
class_def();
}
else {
zzmatch(98);
if ( class_nest_level==0 )
warn("missing class definition for trailing '}'");
}
else break; /* MR6 code for exiting loop "for sure" */
}
}
}
}
}
}
}
}
}
}
{
{
for (;;) {
{
}
}
else {
laction();
}
else {
lmember();
}
else {
lprefix();
}
else {
error();
}
else {
tclass();
}
else {
class_def();
}
else {
aPred();
}
else {
zzmatch(98);
if ( class_nest_level==0 )
warn("missing class definition for trailing '}'");
}
else break; /* MR6 code for exiting loop "for sure" */
}
}
}
}
}
}
}
}
}
}
}
return;
fail:
}
}
void
#ifdef __USE_PROTOS
class_def(void)
#else
#endif
{
{
{
{
}
else {
}
}
}
}
&& GenCC ) {
err("only one grammar class allowed in this release");
go = 0;
}
{
{
if (ClassDeclStuff == NULL) {
/* MR10 */ };
/* MR22 */ do {
/* MR22 */ } while (0);
/* MR10 */
}
}
}
zzmatch(102);
no_classes_found = 0;
else class_nest_level++;
return;
fail:
}
}
void
#ifdef __USE_PROTOS
rule(void)
#else
rule()
#endif
{
{
CurExGroups = NULL;
/* We want a new element label hash table for each rule */
Elabel = newHashTable();
q=NULL;
}
else
{
LATEXT(1),
}
CurRuleNode = q;
NumRules++;
{
{
zzmatch(103);
}
else {
}
}
}
}
{
{
;
{
{
}
else {
}
}
}
}
CurParmDef = pdecl;
}
else {
}
}
}
}
{
{
}
else {
}
}
}
}
{
{
}
else {
}
}
}
}
if ( GenEClasseForRules && q!=NULL ) {
e = newECnode;
else a = q->egroup;
if ( Tnum( a ) == 0 )
{
/* refers to itself */
}
else {
free((char *)e);
}
}
BlkLevel++;
zzmatch(106);
inAlt=1;
CurRuleBlk->file = f;
CurRuleBlk->line = l;
p = newJunction(); /* add EndRule Node */
CurRuleBlk->end = p;
--BlkLevel;
zzmatch(107);
inAlt=0;
{
{
CurRuleBlk->erraction = a;
}
else {
}
}
}
}
{
{
eg = exception_group();
}
}
}
}
CurRuleNode = NULL;
return;
fail:
}
}
void
#ifdef __USE_PROTOS
laction(void)
#else
laction()
#endif
{
{
char *a;
list_add(&LexActions, a);
return;
fail:
}
}
void
#ifdef __USE_PROTOS
lmember(void)
#else
lmember()
#endif
{
{
char *a;
/* MR1 */ if (! GenCC) {
/* MR1 */ } else {
/* MR1 */ };
/* MR1 */
return;
fail:
}
}
void
#ifdef __USE_PROTOS
lprefix(void)
#else
lprefix()
#endif
{
{
char *a;
/* MR1 */ if (! GenCC) {
/* MR1 */ } else {
/* MR1 */ };
/* MR1 */
return;
fail:
}
}
void
#ifdef __USE_PROTOS
aPred(void)
#else
aPred()
#endif
{
{
char *predLiteral=NULL;
int save_file;
int save_line;
int predExprPresent=0;
zzmatch(111);
/* don't free - referenced in predicates */
};
{
{
{
{
predExpr = predOrExpr();
}
else {
}
}
}
}
/*
* predExpr may be NULL due to syntax errors
* or simply omitted by the user
*/
};
};
}
else {
predExpr = predOrExpr();
};
}
}
}
}
{
{
}
else {
}
}
}
}
return;
fail:
}
}
#ifdef __USE_PROTOS
predOrExpr(void)
#else
#endif
{
{
predExpr = predAndExpr();
};
{
{
predExpr = predAndExpr();
};
}
}
}
return _retv;
fail:
return _retv;
}
}
#ifdef __USE_PROTOS
predAndExpr(void)
#else
#endif
{
{
predExpr = predPrimary();
};
{
{
predExpr = predPrimary();
};
}
}
}
return _retv;
fail:
return _retv;
}
}
#ifdef __USE_PROTOS
predPrimary(void)
#else
#endif
{
{
} else {
};
}
else {
predExpr = predOrExpr();
zzmatch(115);
}
else {
predExpr = predPrimary();
}
}
}
return _retv;
fail:
return _retv;
}
}
void
#ifdef __USE_PROTOS
aLexclass(void)
#else
#endif
{
{
return;
fail:
}
}
void
#ifdef __USE_PROTOS
error(void)
#else
error()
#endif
{
{
{
{
;
}
else {
}
}
}
}
e = newECnode;
e->lexclass = CurrentLexClass;
if ( Tnum( (t=StripQuotes(t)) ) == 0 )
{
"hash table mechanism is broken");
}
else
{
free( (char *)e );
go=0;
}
{
{
}
else {
}
else {
}
}
}
}
}
{
{
{
{
}
else {
}
else {
}
}
}
}
}
}
}
}
return;
fail:
}
}
void
#ifdef __USE_PROTOS
tclass(void)
#else
tclass()
#endif
{
{
e = newTCnode;
e->lexclass = CurrentLexClass;
if ( Tnum( t ) == 0 )
{
"hash table mechanism is broken");
p->tclass = e; /* save ptr to this tclass def */
}
else
{
free( (char *)e );
go=0;
}
{
{
/* MR23 */
}
else {
}
}
}
}
/* MR23 */ warnFL(eMsg2("this #tokclass statment conflicts with a previous #tokclass %s(\"%s\") statement",
/* MR23 */ t,p->akaString),
/* MR23 */ };
/* MR23 */ } else {
/* MR23 */ };
/* MR23 */ };
/* MR23 */
{
int zzcnt=1;
{
do {
{
{
if ( go ) {
err("implicit token definition not allowed with #tokdefs");
go = 0;
}
}
{
{
if ( go ) {
err("implicit token definition not allowed with #tokdefs");
go = 0;
} else {
}
}
}
else {
}
}
}
}
}
else {
if ( go ) {
err("implicit token definition not allowed with #tokdefs");
go = 0;
}
}
}
}
}
}
if ( go ) {
} else {
}
}
}
}
return;
fail:
}
}
void
#ifdef __USE_PROTOS
token(void)
#else
token()
#endif
{
{
zzmatch(120);
{
{
{
{
/* MR11 */
}
else {
}
}
}
}
{
{
zzmatch(122);
}
else {
}
}
}
}
}
else {
}
}
}
}
{
{
}
else {
}
}
}
}
{
{
}
else {
}
}
}
}
{
{
}
else {
}
}
}
}
if (t != NULL) {
};
} else {
};
};
};
return;
fail:
}
}
void
#ifdef __USE_PROTOS
#else
#endif
{
{
Graph g, b;
CurBlockID++;
CurAltNum = 1;
{
if (!actionNode->is_predicate )
{
/* MR12c */ };
}
}
{
{
eg = exception_group();
/* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
/* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
}
}
}
}
CurAltNum++;
{
{
zzmatch(123);
inAlt=1;
{
{
eg = exception_group();
/* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
/* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
}
}
}
}
CurAltNum++;
}
}
}
return;
fail:
}
}
void
#ifdef __USE_PROTOS
#else
#endif
{
{
CurAltStart = NULL;
inAlt = 1;
{
{
zzmatch(88);
use_def_MT_handler = 1;
}
else {
}
}
}
}
{
{
;
{
{
old_not=0;
zzmatch(124);
old_not=1;
}
else {
}
}
}
}
n++;
/* record record number of all rule and token refs */
}
}
}
}
}
}
}
if ( n == 0 ) g = emptyAlt();
/* We want to reduce number of LT(i) calls and the number of
* local attribute variables in C++ mode (for moment, later we'll
* do for C also). However, if trees are being built, they
* require most of the attrib variables to create the tree nodes
* with; therefore, we gen a token ptr for each token ref in C++
*/
{
/* This now free's the temp set -ATG 5/6/95 */
}
if ( GenCC ) {
err("one or more $i in action(s) refer to non-token elements");
}
inAlt = 0;
return;
fail:
}
}
#ifdef __USE_PROTOS
element_label(void)
#else
#endif
{
LabelEntry * _retv;
{
UsedNewStyleLabel = 1;
if ( t!=NULL ) {
}
else if ( r!=NULL ) {
}
else {
/* we don't clash with anybody else */
if ( l==NULL ) { /* ok to add new element label */
lab,
/* add to list of element labels for this rule */
_retv = l;
}
else {
}
}
return _retv;
fail:
return _retv;
}
}
Node *
#ifdef __USE_PROTOS
#else
int old_not;
int first_on_line;
int use_def_MT_handler ;
#endif
{
{
int local_use_def_MT_handler=0;
int predMsgDone=0;
int semDepth=0;
int ampersandStyle;
int height; /* MR11 */
int equal_height; /* MR11 */
{
{
label = element_label();
}
else {
}
}
}
}
{
{
err("implicit token definition not allowed with #tokdefs");
}
else {
p->complement = old_not;
}
}
{
{
{
{
}
else {
}
}
}
}
}
else {
}
}
}
}
list_add(&MetaTokenNodes, (void *)p);
{
{
zzmatch(125);
}
else {
}
else {
zzmatch(103);
}
}
}
}
}
{
{
zzmatch(88);
}
else {
}
}
}
}
if ( p!=NULL && first_on_line ) {
p->altstart = CurAltStart;
}
if ( p!=NULL )
}
else {
err("implicit token definition not allowed with #tokdefs");
}
else {
p->complement = old_not;
}
}
{
{
{
{
}
else {
}
}
}
}
}
else {
}
}
}
}
{
{
zzmatch(125);
}
else {
}
else {
zzmatch(103);
}
}
}
}
}
{
{
zzmatch(88);
}
else {
}
}
}
}
list_add(&MetaTokenNodes, (void *)p);
if ( first_on_line ) {
p->altstart = CurAltStart;
}
if ( p!=NULL )
}
else {
{
{
zzmatch(125);
}
else {
}
else {
zzmatch(103);
p->astnode=ASTexclude;
}
}
}
}
}
list_add(&MetaTokenNodes, (void *)p);
if ( first_on_line ) {
p->altstart = CurAltStart;
}
}
}
else {
{
{
zzmatch(103);
q->astnode=ASTexclude;
}
else {
}
}
}
}
{
{
{
{
}
else {
}
}
}
}
}
else {
}
}
}
}
{
{
char *a;
}
else {
}
}
}
}
}
if ( first_on_line ) {
}
}
}
}
}
}
}
}
else {
if ( first_on_line ) { /* MR7 */
};
}
else {
if (numericActionLabel) { /* MR10 */
numericActionLabel=0; /* MR10 */
}; /* MR10 */
{
{
char *a;
}
else {
}
}
}
}
if ( first_on_line ) { /* MR7 */
};
}
else {
BlkLevel++;
{
{
{
{
zzmatch(126);
}
else {
zzmatch(127);
approx = 1;
}
else {
zzmatch(128);
approx = 2;
}
}
}
}
}
}
else {
}
}
}
}
{
{
{
{
/* MR21 */ sizeof(char));
/* MR21 */ "cannot allocate first set name");
/* MR21 */
}
else {
/* MR21 */ sizeof(char));
/* MR21 */ "cannot allocate first set name");
/* MR21 */
}
}
}
}
}
else {
}
}
}
}
{
{
zzmatch(115);
--BlkLevel;
{
{
zzmatch(129);
}
else {
zzmatch(130);
}
else {
{
{
{
{
zzmatch(132);
}
else {
zzmatch(113);
}
}
}
}
if (numericActionLabel) { /* MR10 */
numericActionLabel=0; /* MR10 */
}; /* MR10 */
{
{
char *a;
}
else {
}
}
}
}
if ( first_on_line) { /* MR7 */
};
} else { /* MR10 */
/* MR13 */ if (! equal_height) {
/* MR13 */ };
/* MR13 */ }
/* MR10 */ if (ampersandStyle) {
/* MR11 */ if (! HoistPredicateContext) {
/* MR11 */ };
/* MR10 */ } else {
/* MR10 */ };
/* MR10 */ };
}
}
else {
FoundGuessBlk = 1;
if ( ! first_on_line ) {
err("(...)? predicate must be first element of production");
}
}
}
}
}
}
else {
}
}
}
}
}
}
if ( first_on_line ) { /* MR7 */
}; /* MR7 */
}
}
else {
--BlkLevel;
zzmatch(98);
if ( first_on_line ) { /* MR7 */
};
}
}
}
}
}
else {
zzmatch(129);
}
else {
zzmatch(130);
}
else {
zzmatch(105);
}
else {
warn("[...] out of context 'rule > [...]'");
}
}
}
}
}
}
}
}
return _retv;
fail:
return _retv;
}
}
void
#ifdef __USE_PROTOS
#else
#endif
{
{
return;
fail:
}
}
#ifdef __USE_PROTOS
exception_group(void)
#else
#endif
{
{
zzmatch(133);
{
{
char *p;
{
}
}
else {
}
}
}
}
{
{
h = exception_handler();
}
}
}
{
{
{
}
}
else {
}
}
}
}
/* Record ex group in sym tab for this label */
} else {
/* Label the exception group itself */
/* Make the labelled element pt to the exception also */
/* MR6 */ } else {
case nRuleRef :
{
break;
}
case nToken :
{
break;
}
} /* end switch */
/* MR6 */ }; /* end test on label->elem */
} /* end test on label->ex_group */
} /* end test on exception label */
/* MR7 */
/* MR7 */ } else {
/* MR7 */ };
/* MR7 */
/* MR7 */ /* You may want to remove this exc from the rule list */
/* MR7 */ /* and handle at the labeled element site. */
/* MR7 */
/* MR7 */ };
return _retv;
fail:
return _retv;
}
}
#ifdef __USE_PROTOS
exception_handler(void)
#else
#endif
{
{
;
zzmatch(135);
{
{
}
else {
}
}
}
}
{
{
}
else {
}
}
}
}
return _retv;
fail:
return _retv;
}
}
void
#ifdef __USE_PROTOS
#else
char *fname ;
#endif
{
{
{
{
{
{
}
else {
}
}
}
}
}
else {
}
}
}
}
{
{
{
int zzcnt=1;
{
do {
}
}
}
else {
}
}
}
}
}
else {
}
}
return;
fail:
}
}
void
#ifdef __USE_PROTOS
#else
char *fname ;
#endif
{
{
int v; int maxt=(-1); char *t;
{
int zzcnt=1;
{
do {
/* fprintf(stderr, "#token %s=%d\n", t, v);*/
/* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
/* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
/* MR2 Don't let #tokdefs be confused by */
/* MR2 DLGminToken and DLGmaxToken */
if ( ! isDLGmaxToken(t)) { /* MR2 */
TokenNum = v;
if ( Tnum( t ) == 0 ) {
addForcedTname( t, v );
} else {
};
};
}
}
return;
fail:
}
}
void
#ifdef __USE_PROTOS
#else
char *fname ;
#endif
{
{
int v= 0; int maxt=(-1); char *t;
{
{
}
else {
v++;
}
}
}
}
/* fprintf(stderr, "#token %s=%d\n", t, v);*/
TokenNum = v;
if ( Tnum( t ) == 0 ) addForcedTname( t, v );
else {
}
{
{
{
{
if (!(isDLGmaxToken(LATEXT(1))) ) {zzfailed_pred(" isDLGmaxToken(LATEXT(1))",0 /* report */, { 0; /* no user action */ } );}
{
{
}
else {
}
}
}
}
}
else {
{
{
}
else {
v++;
}
}
}
}
/* fprintf(stderr, "#token %s=%d\n", t, v);*/
TokenNum = v;
if ( Tnum( t ) == 0 ) addForcedTname( t, v );
else {
}
}
else {
}
}
}
}
}
}
}
}
zzmatch(156);
return;
fail:
}
}
/* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
/* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
/* MR2 Don't let #tokdefs be confused by */
/* MR2 DLGminToken and DLGmaxToken */
/* semantic check on DLGminToken and DLGmaxmaxToken in #tokdefs */
#ifdef __USE_PROTOS
static int isDLGmaxToken(char *Token)
#else
static int isDLGmaxToken(Token)
char * Token;
#endif
{
static char checkStr1[] = "DLGmaxToken";
static char checkStr2[] = "DLGminToken";
return 1;
return 1;
else
return 0;
}
/* semantics of #token */
static void
#ifdef __USE_PROTOS
#else
char *t, *e, *a;
int tnum;
#endif
{
TermEntry *p;
/* check to see that they don't try to redefine a token as a token class */
if ( t!=NULL ) {
return;
}
}
err("#token requires at least token name or rexpr");
}
if ( UserDefdTokens ) { /* if #tokdefs, must not define new */
if ( p == NULL) {
err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t));
return;
};
}
Tklink(t, e);
if ( a!=NULL ) {
if ( hasAction(e) ) {
}
else setHasAction(e, a);
}
}
else if ( t!=NULL ) { /* only one found */
if ( UserDefdTokens ) {
if (p == NULL) {
err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t));
};
return;
}
else {
}
if ( a!=NULL ) {
free((char *)a);
}
}
else if ( e!=NULL ) {
else {
if ( hasAction(e) ) {
}
else if ( a==NULL ) {
}
}
if ( a!=NULL ) setHasAction(e, a);
}
/* if a token type number was specified, then add the token ID and 'tnum'
* pair to the ForcedTokens list. (only applies if an id was given)
*/
{
{
}
else
{
}
}
}
static int
#ifdef __USE_PROTOS
match_token(char *s, char **nxt)
#else
match_token(s,nxt)
char *s;
char **nxt;
#endif
{
if ( !(*s>='A' && *s<='Z') ) return 0;
s++;
while ( (*s>='a' && *s<='z') ||
(*s>='A' && *s<='Z') ||
(*s>='0' && *s<='9') ||
*s=='_' )
{
s++;
}
if ( *s!=' ' && *s!='}' ) return 0;
*nxt = s;
return 1;
}
static int
#ifdef __USE_PROTOS
match_rexpr(char *s, char **nxt)
#else
match_rexpr(s,nxt)
char *s;
char **nxt;
#endif
{
if ( *s!='"' ) return 0;
s++;
while ( *s!='"' )
{
if ( *s=='\n' || *s=='\r' ) /* MR13 */
warn("eoln found in regular expression");
if ( *s=='\\' ) s++;
s++;
}
*nxt = s+1;
return 1;
}
/*
* Walk a string "{ A .. Z }" where A..Z is a space separated list
* of token references (either labels or reg exprs). Return a
* string "inlineX_set" for some unique integer X. Basically,
* we pretend as if we had seen "#tokclass inlineX { A .. Z }"
* on the input stream outside of an action.
*/
char *
#ifdef __USE_PROTOS
inline_set(char *s)
#else
inline_set(s)
char *s;
#endif
{
char *nxt;
while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
if ( *s!='{' )
{
err("malformed consumeUntil( {...} ); missing '{'");
return "bad_set";
}
s++;
while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
while ( *s!='}' )
{
else {
err("invalid element in consumeUntil( {...} )");
return "bad_set";
}
s = nxt;
while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
}
return "inlineX_set";
}
/* ANTLR-specific syntax error message generator
* (define USER_ZZSYN when compiling so don't get 2 definitions)
*/
void
#ifdef __USE_PROTOS
int k, char *bad_text)
#else
int tok;
int etok;
int k;
#endif
{
else
{
}
}