Posted By:
SRIRAM_SRINIVASAN
Posted On:
Tuesday, November 13, 2001 07:58 PM
Anu,
There is a mismatch between your example and the grammer.
Your example indicates a higher precedence for assignment than the other operators. That is, in (a=b AND c=d), I presume you want to have a=b and c=d evaluated first. Did you really have assignment or equality in mind here?
In any case, this is not what your grammar does.
Assuming you want the conventional expression grammar, I went ahead and corrected a few things in order to get it to compile.
There are three ambiguities in the parse grammar and one in the lexer.
A left paren starts both an expression and a block. No amount of lookahead can fix that. The easiest option is to make it look like c-like programming languages, and to have the block start with a different character, a left_curly.
block
: LCURLY^ (statement)* RCURLY!
You need to explicitly turn off the ambig warnings in the following two cases, because antlr does the right thing by default (being greedy).
: "if"^ LPAREN! expr RPAREN! statement
(options warnWhenFollowAmbig=false;}: "else"! statement )?
and,
mexpr
: atom (options {warnWhenFollowAmbig=false;}:(OR^ | NOT^) atom)*
The lexer has an ambiguity between ID and STRING. Both start with a letter.
I have a suspicion you meant to make STRING a literal in quotes.
Hope this helps.
-Sriram