[antlr-interest] Is this a bug in Antlr?
Duncan Booth
duncan at rcp.co.uk
Fri Aug 8 01:26:00 PDT 2003
mzukowski at yci.com wrote in
news:72C9789739C4214096AE945753B11EA36B1D30 at mypxmail04.bco-home.com:
>
> I recommend using the -traceParser option when invoking antlr.Tool to
> see what is going on. Also read through the generated code and see
> which test is failing and throwing that exception. That may give us a
> clue.
>
Ok, I just wanted to be sure it wasn't something stupid before I posted too
much information.
The problem is that it is throwning NoViableAltException in the method
'factor'. Output with -traceParser:
> expr; LA(1)==(, LA(2)==a
> term; LA(1)==(, LA(2)==a
> factor; LA(1)==(, LA(2)==a
> atom; LA(1)==(, LA(2)==a
> expr; LA(1)==a, LA(2)==)
> term; LA(1)==a, LA(2)==)
> factor; LA(1)==a, LA(2)==)
> atom; LA(1)==a, LA(2)==)
< atom; LA(1)==), LA(2)==
Unhandled Exception: line 0:0: unexpected token: [")",<5>,line=0,col=0]
< factor; LA(1)==), LA(2)==
< term; LA(1)==), LA(2)==
< expr; LA(1)==), LA(2)==
< atom; LA(1)==), LA(2)==
< factor; LA(1)==), LA(2)==
< term; LA(1)==), LA(2)==
< expr; LA(1)==), LA(2)==
And the factor method looks like:
public void factor() //throws RecognitionException, TokenStreamException
{
traceIn("factor");
try { // debugging
returnAST = null;
ASTPair currentAST = new ASTPair();
AST factor_AST = null;
atom();
astFactory.addASTChild(currentAST, returnAST);
{
switch ( LA(1) )
{
case LPAR:
{
trailer();
astFactory.addASTChild(currentAST, returnAST);
break;
}
case EOF:
case 6:
case 7:
case 8:
case 9:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
factor_AST = currentAST.root;
returnAST = factor_AST;
}
finally
{ // debugging
traceOut("factor");
}
}
Also GrammarTokenTypes:
// $ANTLR 2.7.2: grammar.g -> GrammarTokenTypes.txt$
Grammar // output token vocab name
LPAR="("=4
RPAR=")"=5
"+"=6
"-"=7
"*"=8
"/"=9
NAME=10
NUMBER=11
LITERAL_for="for"=12
LITERAL_in="in"=13
LITERAL_if="if"=14
When I make a minor change to the grammar, such as commenting out the line
"list_for |" in list_iter, I get this in the middle of factor:
case EOF:
case RPAR:
case 6:
case 7:
case 8:
case 9:
{
break;
}
which is what I would have expected.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list