[antlr-interest] Walking AST, and rule dilemma
subhobrotosinha at rediffmail.com
Sat Jun 25 11:24:58 PDT 2005
I want to walk exprs. like "a = 5 + b" [AST : ( = a ( + 5 b ) )], using something like :
#(PLUS in2:INT statement)
show(";add to it '" + in2->getText() + "'");
but I have a rule #(PLUS id2:ID statement) is already defined [ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*; INT : ('0'..'9')+]
The later rule matches exprs. like "a = b + 5" - but it's obvious that this rule will not match the first expression. If I would have tried to incorporate both rules, it would be a non-deterministic rule
What do I do ?
Also, how do I handle exprs. like "a = b" ?
For example, if such exprs. are encountered, I would like to print "'b' is assigned to 'a'"
The complete ANTLR grammar containing these rules is available at http://www.geocities.com/subhobrotosinha/novel.txt
The driver (C++) is available at http://www.geocities.com/subhobrotosinha/noveldriver.txt
It should be obvious that I have been using ANTLR seriously for the last 6 hours, so PLEASE make comments regarding my approach and code, even if you cannot help me out re. this topic.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest