> 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??
You're missing that ANTLR is a LL-Parser. LL-Parser <http://en.wikipedia.org/wiki/LL_parser> work by calling the rules directly (transformed into the correct source code). Thus your changes would result in an infinite loop (atom includes a call to expr, I think). Johannes > > 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')+; -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 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 -~----------~----~----~----~------~----~------~--~---
