[antlr-interest] Bug or misunderstanding?: missing attribute access on rule scope

Kaleb Pederson kaleb.pederson at gmail.com
Fri Oct 16 14:32:24 PDT 2009


On Fri, Oct 16, 2009 at 2:15 PM, David-Sarah Hopwood
<david-sarah at jacaranda.org> wrote:
> Kaleb Pederson wrote:
>> I'm getting an error that doesn't make any sense, either because I've
>> missed something fundamental or I've stumbled across a bug. I'm doing
>> some type checking within a tree parser.  I have a plusMinusExpression
>> which can either be a negation or a subtraction expression.  In order
>> to to check to see which it is, I have `if ($rhs != null)` within my
>> action.  That line, however, causes the following error:
>>
>> SemanticChecker.g:163:3: missing attribute access on rule scope: rhs
>
> You can use "if ($rhs.tree != null)".

You're right, thank you.  Here's what ANTLR generates:

...
if ((rhs!=null?((CommonTree)rhs.tree):null) != null)
{
	typeChecker.assertIsNumericType((rhs!=null?rhs.type:null));
	typeChecker.assertEqualTypes((lhs!=null?lhs.type:null),
(rhs!=null?rhs.type:null));
}

So it places a guard around my check making sure that it only happens
if rhs isn't null.  To pose my next question, isn't what I had
perfectly legal? I.e. Isn't it pefectly legal to reference $labelName
without referencing an attribute, such as in my null check?

--
Kaleb Pederson

Twitter - http://twitter.com/kalebpederson
Blog - http://kalebpederson.com


More information about the antlr-interest mailing list