[antlr-interest] Bug in tree construction generated code
Pete Forman
pete.forman at westerngeco.com
Tue Jan 14 02:32:17 PST 2003
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/
More information about the antlr-interest
mailing list