[antlr-interest] [Q] how rewrite tree for this simple rule with alternatives?

Jim Idle jimi at temporal-wave.com
Sat Oct 15 14:38:02 PDT 2011


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ruslan Zasukhin
> Sent: Saturday, October 15, 2011 7:54 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] [Q] how rewrite tree for this simple rule
> with alternatives?
>
> Hi All,
> Hi Terrence,
>
>
> What still wonders me a lot in ANTLR v3  is that fact that we must
> quite often to use helper rules_leafs to build trees.
>


> ============================================
> Because attempts to make it in SINGLE rule way  -- not works:
>
> alter_trigger_statement
>     :    T_ALTER T_TRIGGER trigger_name ( T_ENABLE | T_DISABLE )
>             -> ^( ALTER_TRIGGER trigger_name (T_ENABLE | T_DISABLE) )
>     ;
>
>
> PROBLEM comes from this alternative (T_ENABLE | T_DISABLE ) ...
> We cannot label it right?
>
> And it is wrong make both tokens optional
>
> alter_trigger_statement
>     :    T_ALTER T_TRIGGER trigger_name ( T_ENABLE | T_DISABLE )
>             -> ^( ALTER_TRIGGER trigger_name T_ENABLE? T_DISABLE? )
>     ;
>


-> ^( ALTER_TRIGGER trigger_name T_ENABLE? T_DISABLE? )

You just have to think about the rewrite ordinality indicators, not the
rule syntax.


Jim


More information about the antlr-interest mailing list