I have a grammar. I run Antlr. In the generated Java...
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Lee_Meador
Posted On:   Tuesday, December 12, 2000 11:36 AM

I have a grammar. I run Antlr. In the generated Java class, the method nextToken() contains this uncompilable code: if ((LA(1)=='[') && (_tokenSet_0.member(LA(2)))) { mITERATION_STRING(true); theRetToken=_returnToken; } else { mDOC(true); theRetToken=_returnToken; } else { mNESTED_DOC(true); theRetToken=_returnToken; } Which, as you can see, has an "if ( ... )" missing after the first else. I am only generating a fairly simple lexer. There are three unprotected rules that I call from different   More>>

I have a grammar. I run Antlr. In the generated Java class, the method nextToken() contains this uncompilable code:



if ((LA(1)=='[') && (_tokenSet_0.member(LA(2)))) {

mITERATION_STRING(true);

theRetToken=_returnToken;

}

else {

mDOC(true);

theRetToken=_returnToken;

}

else {

mNESTED_DOC(true);

theRetToken=_returnToken;

}




Which, as you can see, has an "if ( ... )" missing after the first else.


I am only generating a fairly simple lexer. There are three unprotected rules that I call from different places in my code. The problem likely stems from two of the unprotected rules being pretty much ambiguous until you get deeper inside.


Antlr seems to leave off the if because it can't disambiguate the two rules in nextToken(). But I don't care about nextToken(). I don't have a parser and don't call it myself.


Any ideas on how to keep Antlr from generating uncompilable Java, short of making two lexers with the ambiguous rules, one to a lexer? I would prefer to share the rules.


Can I tell Antlr to not generate a nextToken()?

   <<Less
About | Sitemap | Contact