[antlr-interest] why are these productions different
John Tijoe
john.tijoe at googlemail.com
Wed Jun 24 11:41:15 PDT 2009
Hello,
I was playing with antlrworks and tried to understand the SimpleCalc demo.
And tried to write the expr and the multexpr in a more readable way (at
least to me). But my expr and multexpr seem to be different. Can someone
tell me why they are different I always get the error:
SimpleCalc.g:31:10: [fatal] rule multExpr has non-LL(*) decision due to
recursive rule invocations reachable from alts 1,2. Resolve by
left-factoring or using syntactic predicates or using backtrack=true option.
What Am I missing??
except from it:
WORKING --> expr : multExpr ((PLUS | MINUS ) multExpr)*;
NOT WORKING --> expr : multExpr PLUS multExpr
| multExpr MINUS multExpr
| multExpr
;
NOT WORKING --> multExpr : atom ((MULT | DIV) atom )*;
NOT WORKING --> multExpr : atom MULT atom
| atom DIV atom
atom
;
Best regard John
PS:
Whole grammar
grammar SimpleCalc;
tokens {
PLUS = '+' ;
MINUS = '-' ;
MULT = '*' ;
DIV = '/' ;
RPAREN = ')' ;
LPAREN = '(' ;
ASSIGN = '=' ;
}
/*----------------
* PARSER RULES
*----------------*/
prog : stat+ EOF;
stat : expr NEWLINE
| ID ASSIGN expr NEWLINE
| NEWLINE; //Do nothing
expr : multExpr ((PLUS | MINUS ) multExpr)*;
/*expr : multExpr PLUS multExpr
| multExpr MINUS multExpr
| multExpr
;
*/
//multExpr : atom ((MULT | DIV) atom )*;
multExpr : atom MULT atom
| atom DIV atom
atom
;
atom : INT
| ID
| LPAREN expr RPAREN;
/*----------------
* LEXER RULES
*----------------*/
ID : ('a'..'z'|'A'..'Z')+;
INT : '0'..'9'+;
NEWLINE : '\r'?'\n';
WS : (' '|'\t'|'\n'|'\r')+;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090624/613c11a6/attachment.html
More information about the antlr-interest
mailing list