2N/A * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
2N/A * Purdue University Electrical Engineering
2N/A * With AHPCRC, University of Minnesota
2N/A * ANTLR Version 1.33MR33
2N/A#define ANTLR_VERSION 13333
2N/A#define zzcr_attr(attr,tok,t)
2N/A (*zzerr)("invalid token");
2N/A/* maintained, but not used for now */
2N/Aset AST_nodes_refd_in_actions = set_init;
2N/Aset attribsRefdFromAction = set_init; /* MR20 */
2N/Aint UsedOldStyleAttrib = 0;
int UsedNewStyleLabel = 0;
char *inline_set(char *);
/* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */
int tokenActionActive=0; /* MR1 */
getFileNameFromTheLineInfo(char *toStr, char *fromStr)
getFileNameFromTheLineInfo(toStr, fromStr)
if (!fromStr || !toStr) return toStr;
if ( (i == MaxFileName) ||
if ((j == MaxFileName) ||
/* go back until the last / or \ */
/* copy the string after " / or \ into toStr */
for (i=k+1; fromStr[i] != '\"'; i++) {
toStr[i-k-1] = fromStr[i];
/* MR14 end of a block to support #line in antlr source code */
void mark_label_used_in_sem_pred(LabelEntry *le) /* MR10 */
void mark_label_used_in_sem_pred(le) /* MR10 */
require (le->elem->ntype == nToken,"mark_label_used... ntype != nToken");
require (tn->label != 0,"mark_label_used... TokNode has no label");
tn->label_used_in_semantic_pred=1;
/* L o o k F o r A n o t h e r F i l e */
if ( new_input == NULL ) { NLA=Eof; return; }
zzskip(); /* Skip the Eof (@) char
i.e continue */
zzmode(ACTIONS); zzmore();
action_file=CurFile; action_line=zzline;
zzmode(ACTIONS); zzmore();
list_free(&CurActionLabels,0); /* MR10 */
numericActionLabel=0; /* MR10 */
zzmode(STRINGS); zzmore();
zzmode(COMMENTS); zzskip();
warn("Missing /*; found dangling */"); zzskip();
zzmode(CPP_COMMENTS); zzskip();
#line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n)
zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore();
getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr);
#line ~[\n\r]* (\n|\r|\r\n)
warn("Missing <<; found dangling \>\>"); zzskip();
FoundException = 1; /* MR6 */
while ( zzchar==' ' || zzchar=='\t' ) {
if ( zzchar == ':' && inAlt ) NLA = LABEL;
while ( zzchar==' ' || zzchar=='\t' ) {
if ( zzchar == ':' && inAlt ) NLA = LABEL;
warn(eMsg1("unknown meta-op: %s",LATEXT(1))); zzskip();
warn("eoln found in string");
zzmode(ACTIONS); zzmore();
warn("eoln found in string (in user action)");
zzmode(ACTIONS); zzmore();
warn("eoln found in char literal (in user action)");
zzmode(ACTIONS); zzmore();
zzline++; zzmore(); DAWDLE;
zzline++; zzmore(); DAWDLE;
zzline++; zzmode(PARSE_ENUM_FILE); zzskip(); DAWDLE;
zzline++; zzmode(ACTIONS); zzmore(); DAWDLE;
zzline++; zzmode(START); zzskip(); DAWDLE;
zzline++; zzskip(); DAWDLE;
err( eMsgd("action buffer overflow; size %d",ZZLEXBUFSIZE));
/* MR1 10-Apr-97 MR1 Previously unable to put right shift operator */
/* MR1 Doesn't matter what kind of action it is - reset*/
tokenActionActive=0; /* MR1 */
err( eMsgd("predicate buffer overflow; size %d",ZZLEXBUFSIZE));
/* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred);
/* MR10 */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred);
/* MRxx */ list_apply(CurActionLabels, (void (*)(void *))mark_label_used_in_sem_pred);
/* MR10 */ list_apply(CurActionLabels,mark_label_used_in_sem_pred);
if ( istackempty() ) /* terminate action */
err( eMsgd("parameter buffer overflow; size %d",ZZLEXBUFSIZE));
/* terminate $[..] and #[..] */
if ( GenCC ) zzreplstr("))");
else if ( topint() == '|' ) { /* end of simple [...] */
consumeUntil\( [\ \t]* \{~[\}]+\} [\ \t]* \)
zzreplstr(inline_set(zzbegexpr+
strlen("consumeUntil(")));
zzline++; zzmore(); DAWDLE;
if ( !GenCC ) {zzreplstr("zzaRet"); zzmore();}
else err("$$ use invalid in C++ mode");
if ( !GenCC ) {zzreplstr("zzempty_attr"); zzmore();}
else err("$[] use invalid in C++ mode");
if ( !GenCC ) zzreplstr("zzconstr_attr(");
else err("$[..] use invalid in C++ mode");
numericActionLabel=1; /* MR10 */
if ( strlen(zzbegexpr)>(size_t)85 )
fatal("$i attrib ref too big");
set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction);
if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s)",
else sprintf(buf,"_t%d%s",
err("cannot mix old-style $i with new-style labels");
numericActionLabel=1; /* MR10 */
if ( strlen(zzbegexpr)>(size_t)85 )
fatal("$
i.field attrib ref too big");
zzbegexpr[strlen(zzbegexpr)-1] = ' ';
set_orel(atoi(zzbegexpr+1), &attribsRefdFromAction);
if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%d,%s).",
else sprintf(buf,"_t%d%s.",
err("cannot mix old-style $i with new-style labels");
static char i[20], j[20];
numericActionLabel=1; /* MR10 */
if (strlen(zzbegexpr)>(size_t)85) fatal("$
i.j attrib ref too big");
for (p=zzbegexpr+1,q= &i[0]; *p!='.'; p++) {
fatalFL("i of $
i.j attrib ref too big",
FileStr[CurFile], zzline );
for (p++, q= &j[0]; *p!='\0'; p++) {
fatalFL("j of $
i.j attrib ref too big",
FileStr[CurFile], zzline );
if ( !GenCC ) sprintf(buf,"zzaArg(zztasp%s,%s)",i,j);
else sprintf(buf,"_t%s%s",i,j);
err("cannot mix old-style $i with new-style labels");
{ static char buf[300]; LabelEntry *el;
strcmp(CurRule, &zzbegexpr[1])==0 ) {
if ( !GenCC ) zzreplstr("zzaRet");
else if ( CurRetDef != NULL &&
strmember(CurRetDef, &zzbegexpr[1])) {
if ( hasMultipleOperands( CurRetDef ) ) {
require (strlen(zzbegexpr)<=(size_t)285,
"$retval attrib ref too big");
sprintf(buf,"_retv.%s",&zzbegexpr[1]);
else if ( CurParmDef != NULL &&
strmember(CurParmDef, &zzbegexpr[1])) {
else if ( Elabel==NULL ) {
{ err("$-variables in actions outside of rules are not allowed"); }
} else if ( (el=(LabelEntry *)hash_get(Elabel, &zzbegexpr[1]))!=NULL ) {
/* MR10 */ /* element labels might exist without an elem when */
/* MR10 */ /* it is a forward reference (to a rule) */
/* MR10 */ if ( GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) )
/* MR10 */ { err(eMsg1("There are no token ptrs for rule references: '$%s'",&zzbegexpr[1])); }
/* MR10 */ if ( !GenCC && (el->elem == NULL || el->elem->ntype==nRuleRef) && GenAST) {
/* MR10 */ err("You can no longer use attributes returned by rules when also using ASTs");
/* MR10 */ err(" Use upward inheritance (\"rule >[Attrib a] : ... <<$a=...\>\>\")");
/* MR10 */ /* keep track of <<... $label ...>> for semantic predicates in guess mode */
/* MR10 */ /* element labels contain pointer to the owners node */
/* MR10 */ if (el->elem != NULL && el->elem->ntype == nToken) {
/* MR10 */ list_add(&CurActionLabels,el);
warn(eMsg1("$%s not parameter, return value, (defined) element label",&zzbegexpr[1]));
zzreplstr("(*_root)"); zzmore(); chkGTFlag();
if (NewAST) zzreplstr("(newAST)");
else zzreplstr("(new AST)");}
else {zzreplstr("zzastnew()");} zzmore();
zzreplstr("NULL"); zzmore(); chkGTFlag();
if ( strlen(zzbegexpr)>(size_t)85 )
fatal("#i AST ref too big");
if ( GenCC ) sprintf(buf,"_ast%d%s",BlkLevel-1,zzbegexpr+1);
else sprintf(buf,"zzastArg(%s)",zzbegexpr+1);
set_orel(atoi(zzbegexpr+1), &AST_nodes_refd_in_actions);
#line[\ \t]* [0-9]+ {[\ \t]* \"~[\"]+\" ([\ \t]* [0-9]*)* } (\n|\r|\r\n)
zzline = atoi(zzbegexpr+5) - 1; zzline++; zzmore();
getFileNameFromTheLineInfo(FileStr[CurFile], zzbegexpr);
#line ~[\n\r]* (\n|\r|\r\n)
if ( !(strcmp(zzbegexpr, "#ifdef")==0 ||
strcmp(zzbegexpr, "#if")==0 ||
strcmp(zzbegexpr, "#else")==0 ||
strcmp(zzbegexpr, "#endif")==0 ||
strcmp(zzbegexpr, "#ifndef")==0 ||
strcmp(zzbegexpr, "#define")==0 ||
strcmp(zzbegexpr, "#pragma")==0 ||
strcmp(zzbegexpr, "#undef")==0 ||
strcmp(zzbegexpr, "#import")==0 ||
strcmp(zzbegexpr, "#line")==0 ||
strcmp(zzbegexpr, "#include")==0 ||
strcmp(zzbegexpr, "#error")==0) )
sprintf(buf, "%s_ast", zzbegexpr+1);
/* MR27 */ list_add(&CurAstLabelsInActions, mystrdup(zzbegexpr+1));
if (NewAST) zzreplstr("(newAST(");
else zzreplstr("(new AST("); }
else zzreplstr("zzmk_ast(zzastnew(),");
zzreplstr("ASTBase::tmake(");
else if ( topint()==')' ) {
else if ( topint()=='}' ) {
pushint('|'); /* look for '|' to terminate simple [...] */
zzreplstr("]"); zzmore();
zzreplstr(")"); zzmore();
if (! tokenActionActive) zzreplstr(">"); /* MR1 */
zzmode(ACTION_CHARS); zzmore();
zzmode(ACTION_STRINGS); zzmore();
zzreplstr("$"); zzmore();
zzreplstr("#"); zzmore();
zzmode(ACTION_COMMENTS); zzmore();
warn("Missing /*; found dangling */ in action"); zzmore();
zzmode(ACTION_CPP_COMMENTS); zzmore();
~[\n\r\)\(\\$#\>\]\[\"'/]+
zzmode(TOK_DEF_CPP_COMMENTS); zzmore();
zzmode(TOK_DEF_COMMENTS); zzskip();
zzmode(TOK_DEF_CPP_COMMENTS); zzskip();
zzmode(TOK_DEF_CPP_COMMENTS); zzskip();
zzmode(TOK_DEF_CPP_COMMENTS); zzskip();
zzmode(TOK_DEF_CPP_COMMENTS); zzskip();
zzmode(TOK_DEF_CPP_COMMENTS); zzskip();
zzmode(TOK_DEF_CPP_COMMENTS); zzskip();