[antlr-interest] Get parent of current AST node

David Holroyd dave at badgers-in-foil.co.uk
Mon Oct 9 02:30:00 PDT 2006


On Mon, Oct 09, 2006 at 11:02:11AM +0200, Fridi wrote:
> I'm new to antlr and sorry, if this is a stupid question...
> Is there a way to get the parent of a current AST node?

For antlr v3; supply your own implementation of TreeAdaptor customized
to return instances of DoubleLinkTree (which has the getParent() /
setParent() methods you want).

If you want to access these methods from actions, then you'll also want
to put ASTLabelType=DoubleLinkTree in your grammar's options{} section
to save lots of type-casts.


For antlr v2, I don't remember.  Sorry.  Probably you need to do a
similar trick; make an AST subclass including a 'parent' property and
lots of entries like MY_TOKEN<AST=com.example.MyASTImpl>; in your
grammar's tokens{} section.


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list