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

Mark Langezaal mark.langezaal at xs4all.nl
Mon Oct 13 18:12:07 PDT 2008


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();}
   ;






More information about the antlr-interest mailing list