[antlr-interest] AST construction
victor
noagbodjivictor at gmail.com
Mon Jul 5 06:25:49 PDT 2010
hello list,
i am having trouble constructing my ASTs. i learned how to construct a parse
tree from the book Language Implementation Patterns. in pseudo code, it
looks like this:
func rule:
node = RuleNode('rule_name')
if root is null: root = node
else: current_node.add_child(node)
save = current_node
current_node = r # descend
# now rule code
# goes here
current_node = save # restore
(TokenNodes are created in the match function of the parser) the previous
works fine for constructing a parse tree. but i'm having trouble with an
AST. consider for example the AddNode with the prototype:
AddNode(right_expr, plus, left_expr)
i can't really follow the template above here. the contructor requires
right_expr and the left_expr, which i only get after parsing. i was
wondering how it is usually done in this case.
thanks a lot in advance :)
--
victor
More information about the antlr-interest
mailing list