[antlr-interest] Attribute Access in Tree Grammar Actions

Randall R Schulz rschulz at sonic.net
Fri Jun 29 15:45:21 PDT 2007


On Friday 29 June 2007 15:28, Gavin Lambert wrote:
> At 10:16 30/06/2007, Randall R Schulz wrote:
>  >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 
>
> I think you need to use $equation.value and $atom.value.  Or
> something like that :)

Evidently it's "or something like that."

When I look at the generated source code, equation(), atom() and 
atomicSentence() all declare plain, unadorned Formulas, as their return 
types.

How to I get at the return values of rules when those rules appear on 
the right-hand-side of another rule?


> And I think you're also supposed to say $f rather than just
> f.  Gives the code generator the opportunity to move things around.

Hmm... OK. I see that's what I did in an earlier (non-tree) grammar I 
wrote. But "move things around?" Why would that be a good thing? Order 
of execution is kind of important in imperative languages...


Randall Schulz


More information about the antlr-interest mailing list