[antlr-interest] Understanding the Java Grammar, or Kelcy Grammer
Alexey Demakov
demakov at ispras.ru
Wed Jan 25 23:05:12 PST 2006
Do you have EOF token referenced in parser?
If not, parser just stops without any errors messages
when it reaches unexpected token * after 1*2+3.
Regards,
Alexey
-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
----- Original Message -----
From: "sporty" <spa6 at sporty.org>
To: <antlr-interest at antlr.org>
Sent: Wednesday, January 25, 2006 8:33 PM
Subject: [antlr-interest] Understanding the Java Grammar, or Kelcy Grammer
>I read the Java grammar included w/ antlr, after trying to deal with mathematical equations. I successfully got a parser in the
>form, similar to the java one, to work:
>
> eplus : NUMBER ((PLUS^|MINUS^) NUMBER)* ;
> etimes : eplus ((TIMES^|DIV^) eplus)* ;
> ecomp : etimes ((LT^|GT^|LTE^|GTE^) etimes)* };
> eequal : ecomp ((sequal|nsequal|NEQUAL|NNEQUAL) ecomp)* };
> eor : eequal (OR^ eequal)* ;
> eand : eor (AND^ eor)* };
>
> I can wholeheartedly accept that it works, but I do not understand why as yet. I would expect and equation of the form 1*2+3*4+5
> not to parse. After it parses 1*2+3, I would expect it not to get to 4, since the token after 3 to be a *, and eplus specifies
> +'s and -'s to follow.
>
> But it does, and it doesn't make sense. Hepl?
>
> Thanks,
> -s
More information about the antlr-interest
mailing list