[antlr-interest] Understanding the Java Grammar, or Kelcy Grammer
sporty
spa6 at sporty.org
Wed Jan 25 09:33:26 PST 2006
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