[antlr-interest] custom AST with re-write rules in C runtime
Jim Idle
jimi at temporal-wave.com
Tue Feb 10 08:17:47 PST 2009
Robert Soule wrote:
> 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(..) ?
>
Once you have created the parser, just install a pointer to your own
adaptor. You can also do this in @apifuncs I think. As in:
ADAPTOR = pointerToMyAdaptor;
You adaptor structure needs to be the same structure that the common
adaptor uses and provide the same function set.
To be honest with you, even in Java I have found it easier just to call
my own functions directly from actions and not try and create an
adaptor, thoguh this is essentially because of what type of tree is
needed in the case of errors and so on.
Jim
More information about the antlr-interest
mailing list