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:8080/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
>
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---