[antlr-interest] custom AST with re-write rules in C runtime

Jim Idle jimi at temporal-wave.com
Thu Feb 5 12:26:30 PST 2009


Robert Soule wrote:
> Hi,
>
> I'd like to use my own custom AST instead of the pANTLR_BASE_TREE
> provided in the C runtime. What I was wondering is if I can use antlr's re-write
> rules ( -> ^(...) ) to generate the tree with my own node implementation? If
> so, can you provide any guidance on how to do that?
>
> I've been looking at antlr3basetree.h. Is the idea that we use this
> base tree, but
> set the "u" pointer to our own data structures?
>   
That's by far the easiest way, which is why I did that. Mostly, that's 
all people need. However, you can also write your own tree adaptor that 
just passes around (void *). Not a task for the inexperienced C 
programmer though. But if you copy the adaptor code and fill in your own 
functions, that will work. Much easier to just add your nodes to the u 
pointer though and let the current stuff do all the work :-)

Jim




More information about the antlr-interest mailing list