[antlr-interest] AST if-then-else
Frank Du
frank.du at riskmetrics.com
Mon Jun 1 12:59:34 PDT 2009
Hi Florian,
There are 2 things to resolve your problem:
1. Please use antlr-v3.1.2 instead. I verified a bug in 3.1.3, which caused errors in the tree interpreter example.
2. To implement if-else-statement tree walker, we can use wildcard and tree node stream index jumping. You may want to look at the example implementation by Scott Fortmann-Roe:
http://www.antlr.org/share/1178224532340/cminus.zip
Please let me know if I can get you more information.
Thanks,
Frank Qixing Du
Platform Development Group
RiskMetrics Group, New York
-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Florian Putz
Sent: Monday, June 01, 2009 2:47 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] AST if-then-else
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
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list