At 06:41 25/06/2009, John Tijoe wrote:
>WORKING --> expr : multExpr ((PLUS | MINUS ) multExpr)*;
>
>NOT WORKING --> expr : multExpr PLUS multExpr
> | multExpr MINUS multExpr
> | multExpr
> ;
ANTLR is an LL parser; you must always keep the left-side of a
rule (or rule fragment) unique to avoid ambiguity. This is why
the first works but the second doesn't. (Also, the two aren't
equivalant.) To rewrite it properly, you'd need either this:
expr : multExpr
( PLUS expr
| MINUS expr
)?
;
Or this:
expr : multExpr
( PLUS multExpr
| MINUS multExpr
)*
;
(The second is usually a better pattern to follow; the first can
sometimes get you into trouble.)
>NOT WORKING --> multExpr : atom ((MULT | DIV) atom )*;
>
>NOT WORKING --> multExpr : atom MULT atom
> | atom DIV atom
> atom
> ;
[...]
>atom : INT
> | ID
> | LPAREN expr RPAREN;
The second of these won't work for the same reasons. The first
ought to work fine, though (even with the reference back to expr,
despite what Johannes said).
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---