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

Robert Soule robert.soule at gmail.com
Tue Feb 10 08:06:10 PST 2009


Hi Jim,

I'd like to use my own custom AST and write my own tree adapter.
One thing that I haven't been able to figure out is how to substitute
my adapter for the default adapter when the parser code is generated.

The adapter is declared in the parser header file as:
 pANTLR3_BASE_TREE_ADAPTOR   adaptor;

and then used with the macro definition:
#define     ADAPTOR                         ctx->adaptor

What I was wondering is, is there an option that I can specify to
have antlr generate a parser that refers to my adapter?

 pMY_CUSTOM_TREE_ADAPTOR   adaptor;

and the associated functions like:
ANTLR3_TREE_ADAPTORNew(..) ?

thank you,
Robert


On Thu, Feb 5, 2009 at 3:26 PM, Jim Idle <jimi at temporal-wave.com> wrote:
> 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
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list