[antlr-interest] Line and column numbers in rewrite rules

Andreas Stefik stefika at gmail.com
Thu Jun 11 15:53:26 PDT 2009


It looks like I missed a few posts on this topic from a few days ago
(Thanks, Jim!)

The suggestion appears to pass, for a tree grammar rule like:

expression    returns[ExpressionValue eval]
    :
        ^(PLUS left = expression right = expression)

to use $e.tree and then get the line and column info.

On the Java target, the following:

CommonTree tree = $left.tree;

generates:

CommonTree tree = (left!=null?((CommonTree)left.tree):null);

But there is no variable called tree (apparently). There is, however, a
"getTree()" function, but it doesn't look like ANTLR automatically
translates it into that form, so I assume that's not its intended use. If,
however, I hack the generated code and put in something similar to

(CommonTree)left.getTree()) the result appears to always be null.

Jim, does your solution have some preconditions I'm not seeing?

Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090611/444c22a4/attachment.html 


More information about the antlr-interest mailing list