[antlr-interest] ANTLR3 - Find the parent node in an AST
Gavin Lambert
antlr at mirality.co.nz
Tue Aug 5 13:55:48 PDT 2008
At 22:16 5/08/2008, Johannes Luber wrote:
>You could derive another class from CommonTree which does store
a
>reference to its parent and use it instead of CommonTree. Then
you
>have to find the places where the CommonTree instances are
created
>and modify those to include the parent reference. The easiest
way
>to find all those instances is to enforce the use of this
parameter
>as the compiler will complain about the missing argument.
Possibly
>you have to modify the template files, too, which means you have
to
>recompile the ANTLR tool yourself.
You shouldn't need to go that far. That's what the TreeAdaptor is
for -- to abstract the creation and modification of the AST, so
you can use any type you feel like.
I'm surprised that the CommonTree wouldn't have a reference to its
parent, though. That just seems like it should be automatic for
any tree structure.
More information about the antlr-interest
mailing list