[antlr-interest] How-to: Tree grammar when AST rewrite rules involve parameters?

M. Utku Karataş m.utku.k at gmail.com
Sun Sep 14 02:11:39 PDT 2008


On Sun, Sep 14, 2008 at 5:27 AM, Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 12:50 14/09/2008, =?ISO-8859-2?Q?M._Utku_Karata=BA?= wrote:
<SNIP>
>>messageChain [CommonTree o]
>>      :  ^({(CommonTree)$o} unaryMessageChain binaryMessageChain)
>>      |  ^({(CommonTree)$o} binaryMessage binaryMessageChain)
>
> Well, that's definitely not valid syntax.  It would help if you knew what
> token type that root node is.  Failing that, though, you could always just
> use this:
>
> messageChain
>    : ^(. (unaryMessageChain binaryMessageChain | binaryMessage
> binaryMessageChain))
>    ;

Thanks Gavin, I wasn't aware of '.' notation in rewrite rules (IIRC
not mentioned in the ANTLR reference).

For a workaround - I went with grammar refactorizations instead of
passing parameters around (which tends to get uglier and uglier in
time if you're constantly improvizing on the grammar :)).

Regards,
M. Utku Karatas.


More information about the antlr-interest mailing list