[antlr-interest] "become root" operator ^ sometimes fails

Terence Parr parrt at cs.usfca.edu
Mon Oct 13 18:16:42 PDT 2008


Hi. ('+')^ is probably better as '+'^ since I think there has been  
some subrule-as-set funkiness.
Ter
On Oct 13, 2008, at 6:12 PM, Mark Langezaal wrote:

> Hello,
>
> During the construction of a grammar I encountered an anomaly in the
> creation of root nodes when using the "become root" operator ^.
> I use ANTLRWorks version 1.2
> With the below simplified grammar it can be reproduced.
> The okExpr rule generates the expected AST. for input: 1 + 2
> But the badExpr rule does NOT generate a new root node for '+' token.
>
> Can one of you experts confirm (or deny) this is a genuine problem?
>
> Best regards,
> Mark langezaal
>
> ===================================
> grammar foo;
>
> options {
>   output = AST;
>   ASTLabelType = CommonTree;
> }
>
> // Input: 1 + 2
> // Generated AST: ^(+ 1 2)
> okExpr
>   :    NUM (('+'|'-')^ NUM)*
>   ;
>
> // Input: 1 + 2
> // Generated AST: (1 + 2)
> badExpr
>   :    NUM (('+')^ NUM)*
>   ;
>
> NUM
>   :   ('0'..'9')+
>   ;
>
> WS
>   : ('\r'|'\n'|'\t'|' ')+  {skip();}
>   ;
>
>
>
>
>
> 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