[antlr-interest] Clarification on Attribute Reference in Actions

Kay Roepke kroepke at classdump.org
Wed Jul 4 17:40:02 PDT 2007


On Jul 5, 2007, at 1:31 AM, Kay Roepke wrote:

> I think it is a shortcoming in the ActionParser code. It should  
> warn you that $term.t will refer to the rule's return value if a  
> subtree of the same name is actually visible to the action.
>
> "Bug" just sounded too harsh... ;)

Love talking to myself :)

FYI,
I have a patch for this, it's a bit ugly right now because it has to  
iterate over all rule refs in all visible alts and count those  
without labels.
Apparently there's no mapping available to get all labels for a rule  
in an alt. Guess Ter never needed that yet :) For performance this  
should be available, or even better we could restructure things a  
bit, so that this kind of information doesn't have to live in  
LinkedHashMaps all over the place...

Anyway, this patch needs two things:

1) Attention - need to create a warning in ErrorManager
2) Approval - Ter must say "yes" or "no" ;)

At the latest we'll sort it out during my vacation :)

A quick summary:
What happens is that ANTLR sees the return value member first and  
decides to use that instead of the rule reference. My patch adds code  
to look for unlabeled rule references with the same name (i.e.  
recursive invocations) and warns if there is at least one without a  
label.
Currently it says:
"retval member term.t masks rule ref [@-1,24:27='term',<0>,0:-1]  
retval attribute access"

And no, that won't be actual wording ;)

cheers,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list