[antlr-interest] confused on tree grammar...

Pady Srinivasan padysrini at hotmail.com
Thu Jan 1 00:27:03 PST 2009


If I have a predicate to make a decision on which node to execute, why would 
antlr lookahead into the node before checking on the decision ? So if I have 
a ast as follows -

root --> { condition, trueBlock, falseBlock }

I want

if ( condition )
   trueBlock;
else
   falseBlock;


So I use a predicate in my tree grammar to define this. But antlr always 
generates,

if ( condition && trueBlock )
   trueBlock;
else if ( !condition && falseBlock )
  falseBlock;


If I were to write my own tree walker, I would be doing the former by just 
gettting the children and executing the child method that corresponds to the 
condition. Why would antlr do a lookahead while handling this predicate ?


Thx

-- pady 



More information about the antlr-interest mailing list