[antlr-interest] same character for multiple rules?

Roy Metzger antlrmen at yahoo.com
Tue Jul 5 05:00:12 PDT 2011


Hi and Hello to everyone,

I would really appreciate any hints and advices if someone can give my relating to my problem. I would like to know how to deal with the situation where you would use same character for multiple rules/operations. For example in Visual Basic you use '=' for both variable assignment (a=10) and for comparison (if(a=10 then ....).

Clearly, using assignment rule:assignment:

  ID '=' expression;

and later relation rule:
relation:
atom ('=' atom)*;

gives out error like rule relation has non-LL(*) decision due to recursive rule  invocations reachable from alts 1,6.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
And, yes, it is clear that antlr can not decide when to use assignment and when comparison, makes sense. But, my question is, how to deal with this? I'm not interested in using different characters for rules(e.x. '==' etc.). Is this where I have to look into the backtracking? Or is there some other way, that I'm not aware of?


Help would be most appreciated,
Lee


More information about the antlr-interest mailing list