[antlr-interest] Attribute Access in Tree Grammar Actions

Randall R Schulz rschulz at sonic.net
Fri Jun 29 15:16:07 PDT 2007


Hi,

I'm having trouble figuring out how to access the results returned by
rules in a tree grammar. When I write a rule like this:

atomicSentence
returns [ Formula f ]
  : equation
    {
      f = $equation;
    }

  | atom
    {
      f = $atom;
    }
  ;


I get these diagnostics from ANTLR:

error(117): CLIFBuilder.g:1157:3: missing attribute access on rule scope: equation
error(117): CLIFBuilder.g:1162:3: missing attribute access on rule scope: atom


Both "equation" and "atom" also return Formula, so there ought to be
type compatibility.

I can't find any examples that show non-trivial actions in tree
grammars. I have TDAR, so if there's something in there I'm overlooking,
please refer me to it.


By the way, searching (using Google via the ANTLR home page search
field) for "Tree Parsing Action Attributes" yielded this hit (among many
others): <http://www.antlr.org/wiki/display/ANTLR3/tree+parser+rules+have+different+attributes+than+parser+rules>.
Unfortunately, that page now reads:

"A page with this title has been deleted. Contact your space
administrator if you would like it restored."



Anyway, I'd appreciate knowing what I'm missing or doing wrong.


Randall Schulz


More information about the antlr-interest mailing list