[antlr-interest] Another beginner question
David Smith
david.smith at cc.gatech.edu
Sat May 28 07:29:20 PDT 2011
I need to "wrap" a collection of statements as a code body in order
to mechanize if, for and while loops. In my tree generator, this
works great as:
prog: body EOF! {if($body.tree!=null)
System.out.println($body.tree.toStringTree());}
;
body : parts -> ^(BODY parts)
;
parts:
( (stat
| ifStat) )*
;
This produces, for example, [I inserted some newlines to make it legible]
(BODY (= a 3)
(= b 4)
(if (> a b) (BODY (= a (+ b 1)))
elseif (< a b) (BODY (= b (- a b)) (= c 42) (= d 4))
else (BODY (= b 4) (= c (- a b)))
end)
)
I intend the Java code that implements 'if' to receive the "children"
bodies as sub-trees and invoke the original tree walker on the
appropriate tree. However, I have no idea how the tree walker should
parse ^(BODY parts) to execute each statement in that body.
Any ideas?
DMS
David M. Smith http://www.cc.gatech.edu/fac/David.Smith
Georgia Institute of Technology, College of Computing
Sent from my ASR-33 Teletype
More information about the antlr-interest
mailing list