[antlr-interest] V2 -> V3 rules

g4 at novadsp.com g4 at novadsp.com
Tue Mar 8 10:45:19 PST 2011


Thanks Jim

In order to get the right tree I ended up with this:

rhs
	: a=rhs_alt (OR b=rhs)*
	;


Sorry to labor the point here but what I keep failing to see is how you 
spec a rewrite rule for this kind of expression. I know the default gets 
me what I need but that's not quite the same as knowing :)

I do not want to use the list idiom Ter mentions in the book. Are 
sub-rules the only way to do it?

On 07/03/2011 15:25, Jim Idle wrote:
> rhs : rhs_alt ( OR^ rhs_alt )*;
>
>
>
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>> bounces at antlr.org] On Behalf Of g4 at novadsp.com
>> Sent: Monday, March 07, 2011 6:33 AM
>> To: ANTLR Interest
>> Subject: [antlr-interest] V2 ->  V3 rules
>>
>> I've checked the Migration Wiki and it's a little unclear on how handle
>> the following. The general form is taken from bison.g:
>>
>> V2:
>>
>> rhs : rhs_alt
>>       { ## = #( [ALT, "alt"], #rhs ); }
>>       ( OR^ rhs_alt )*;
>>
>> V3:
>>
>> rhs : (a=rhs_alt ->  $rhs ) (OR b=rhs)*
>>       ;
>>
>> error(132) reference $rhs is ambiguous; rule rhs is enclosing rule and
>> referenced in the production (assuming enclosing rule)
>>
>> V3 - not even sure if this form is legal ...
>>
>> rhs : rhs_alt
>>           { $$ = $([OR,"or"],$rhs); }
>>         (OR^ rhs_alt)*
>>       ;
>>
>> error(117): missing attribute access on rule scope: rhs
>>
>> Thx++
>>
>> Jerry.
>>
>>
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
>> email-address
>
> 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