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

Jim Idle jimi at temporal-wave.com
Sat Oct 17 21:13:31 PDT 2009


You need to rewrite the unary operators with imaginary tokens in your parser, which then means your tree parser need not care:

unary:  PLUS unary -> ^(UPLUS unary)
     | primary
     ;

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kaleb Pederson
> Sent: Saturday, October 17, 2009 12:52 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Bug or misunderstanding?: missing attribute
> access on rule scope
> 
> 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
> 
> The grammar fragment follows:
> 
> plusMinusExpression returns [Type type]
> 	:	^(PLUS lhs=baseExpression rhs=baseExpression) { /*...*/ }
> 		|	^(MINUS lhs=baseExpression rhs=baseExpression?)
> 		{
> 			typeChecker.assertIsNumericType($lhs.type);
> 			if ($rhs != null)
> 			{
> 				typeChecker.assertIsNumericType($rhs.type);
> 				typeChecker.assertEqualTypes($lhs.type,
> $rhs.type);
> 			}
> 			$type = $lhs.type;
> 		}
> 	;
> Am I missing something fundamental or should this work? I tried
> changing rhs to something unique throughout the application, but the
> error persists.  I see the exact same behavior on both ANTLR-3.1 and
> 3.2.
> 
> Thanks.
> 
> --
> Kaleb Pederson
> Twitter - http://twitter.com/kalebpederson
> Blog - http://kalebpederson.com
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list