[antlr-interest] Bug in tree construction generated code

Terence Parr parrt at jguru.com
Wed Jan 15 12:01:30 PST 2003


Hi Pete,

Unfortunately, this is a "feature" that I was uncomfortable with 
introducing way back when that has bitten us all.  STRING is a 
shorthand for a reference to that token in the rule's AST.  :(  I'd be 
happy to remove this ambiguous feature, but it would break a lot of 
code :(

Thanks for the report,
Terence

On Tuesday, January 14, 2003, at 02:32 AM, Pete Forman wrote:

> There is a bug in the code generated from a tree constructor
> illustrated by the following example.
>
> class P extends Parser;
> options {buildAST = true;}
> input: (text | NUMBER)* EOF!;
> text: STRING
>      { ## = #([STRING, "foo"], #STRING);
>      }
>    ;
>
> class L extends Lexer;
> NUMBER: ('0'..'9')+;
> STRING: '\''! (~'\'')* '\''!;
>
> The generated code does not compile.  What has happened is that the
> STRING in [STRING, "foo"] is replaced by a temporary AST from the line
> above instead of an int token.  The #STRING correctly references the
> temporary AST.
>
>
> A workaround is to alias the token name.
>
>      { int STRING2 = STRING; // establish alias
>        ## = #([STRING2, "foo"], #STRING);
>
>
> I came across this problem in 2.7.1 generating Java.  It is still
> present in 2.7.2rc2.
>
>
> BTW, the use of ## in tree construction does not appear to be in the
> documentation.  It is described in */action.g.
>
> -- 
> Pete Forman                -./\.-  Disclaimer: This post is originated
> WesternGeco                  -./\.-   by myself and does not represent
> pete.forman at westerngeco.com    -./\.-   opinion of Schlumberger, Baker
> http://petef.port5.com           -./\.-   Hughes or their divisions.
>
>
>
>
> Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list