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

Robert Soule robert.soule at gmail.com
Tue Feb 10 09:03:46 PST 2009


>>
> 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;
>

OK, thank you. This worked for me, but I end up with code like:

    ADAPTOR     = ANTLR3_TREE_ADAPTORNew(...);
    ctx->vectors        = antlr3VectorFactoryNew(64);

    ADAPTOR = MY_CUSTOM_TREE_ADAPTORNew(...);

Which works, but calls the ANTLR3_TREE_ADAPTORNew unnecessarily.
Is there a way to avoid that?
>
> 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.
>

You mean to use the actions instead of the re-write rules? I can see
that being true, but it does end up tying your grammar in to a specific
generated code. Ideally, I'd like my grammar to be as target-language
agnostic as possible.

thanks for your help,
Robert


More information about the antlr-interest mailing list