[antlr-interest] ANTLR3 - Find the parent node in an AST

Johannes Luber jaluber at gmx.de
Tue Aug 5 03:16:56 PDT 2008


Varun Bhargava schrieb:
> Hi All,
> 
>  
> 
> I’m using ANTLR3 and C# as my target language.
> 
>  
> 
> When I go through my tree, I noticed that the CommonTree class does not 
> have a reference to its parent node. How can I achieve this functionality?

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.

Johannes
> 
>  
> 
> Thanks
> 
> Varun
> 



More information about the antlr-interest mailing list