[antlr-interest] Bug in tree construction generated code

Luke Evans luke.evans at seagatesoftware.com
Wed Jan 15 13:49:16 PST 2003


This might seem like overkill - and I guess there's plenty more to worry
about than this sort of minutia, however...

Have you thought of having a 'deprecated' flag which would be used to
control features of this sort?  Such a feature may, or may not, imply if or
when a 'legacy' feature might be removed from the product, but at the very
least it provides a 'large hint' as to what represents 'sanctioned' features
in a given version.  Probably it's nice to discourage new users/projects
from engaging features which are no longer considered 'best practice' or for
which there are better alternatives.

Lwe

> ----------
> From: 	Terence Parr
> Reply To: 	antlr-interest at yahoogroups.com
> Sent: 	Wednesday, January 15, 2003 12:01 PM
> To: 	antlr-interest at yahoogroups.com
> Subject: 	Re: [antlr-interest] Bug in tree construction generated code
> 
> 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/ 
> 
> 
> 

 

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



More information about the antlr-interest mailing list