[antlr-interest] AST if-then-else

Florian Putz flo.putz at gmail.com
Mon Jun 1 11:46:38 PDT 2009


Hello,

I have a parser grammar that creates an AST. My rule for if-then-else 
looks like:

e     :  (IF cond=p THEN ifStat=e ELSE elseStat=e ENDIF ) -> ^(IF $cond 
$ifStat $elseStat)

This creates a correct AST node containing the IF and its children. In 
my tree grammar I match the node now with this rule:

e : ^(IF cond=p ifstat=e elstat=e)

The matching also works fine. My problem is now that I did not find a 
single working example on the web and neither in the book of how to 
evaluate ifstat and elstat. PS: I use the latest ANTLR Release (3.1.3). 
There is an example at 
http://www.antlr.org/wiki/display/CS652/Tree-based+interpreters, but it 
also does not work. I just want to know how the java code would look 
like to execute either the then or the else part of the subtree.

Any help greatly appricited.

Thx in advance,
flo


More information about the antlr-interest mailing list