[antlr-interest] Ambiguous reference
Jim Idle
jimi at temporal-wave.com
Thu Nov 18 09:23:28 PST 2010
It is a little overzealous in its warning but it isn't failing ;-)
The warning is telling you that it is picking the correct interpretation,
but the label of the rule reference should of course suppress the warning.
I should also point out that using an entire expression reference as a
predicate (especially in this case) will be very slow and indicates that the
grammar is poorly formed. I suspect that you (Tomas) are following a written
spec too closely and are really trying to implement right associativity.
I also suspect that overall, you need to start again but this time left
factor as you go. Remember that the spec you are working from is probably
written in LALR terms, that you will need to interpolate before typing in to
an ANTLR grammar spec. If you are not working from a spec then stepping back
and reconsidering the syntax may be in order.
What language are you trying to parse and what spec are you using? I think
that you may be asking the wrong questions :)
Look more at a construct like this (I am guessing at what you are ultimately
trying to do of course):
expression
: p=paring e=expression
-> ^(APPLY $p $e)
| expr2
;
expr2
: expr3 (OPER expr3)*
;
etc
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Sam Harwell
> Sent: Thursday, November 18, 2010 8:33 AM
> To: 'Prerovsky, Tomas'; antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Ambiguous reference
>
> Hi Tomas,
>
> This is the first time I've seen someone else mention this. If you look
> at all the ways this could be written, it's clear that there is no
> ambiguity, so ANTLR is incorrectly failing:
>
> VALID: If the rhs expression is not labeled (first example), then its
> reference in a rewrite rule doesn't use a $ sign. If the rhs is labeled
> (second example), then its label is different from the enclosing rule's
> name.
>
> expression : (pairing->pairing) (expression -> ^(APPLY $expression
> expression));
>
> expression : (pairing->pairing) (rhs=expression -> ^(APPLY $expression
> $rhs));
>
> INVALID: The only actual way to introduce an ambiguity is to write the
> rule in the following way. However, it is an error in ANTLR to have the
> name of any rule as a label anywhere in the grammar. This restriction
> guarantees that there can never be an ambiguity when rewriting the rule
> as you were trying to.
>
> expression : (pairing->pairing) expression=expression -> ^(APPLY
> $expression $expression);
>
> Sam
>
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Prerovsky, Tomas
> Sent: Thursday, November 18, 2010 9:50 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Ambiguous reference
>
> Hi,
>
> the following line :
>
> expression
> :
> (pairing->pairing) ( (expression)=> rhs=expression -> ^(APPLY
> $expression
> $rhs) | ) ;
>
> causes in the latest build of ANTLR 3.2 (Sep 23, 2009) the error:
>
> "reference $expression is ambiguous; rule expression is enclosing rule
> and referenced in the production (assuming enclosing rule) |--->
> (pairing->pairing) ( (expression)=> rhs=expression -> ^(APPLY
> $expression
> $rhs) | ) "
>
>
> ANTLR 3.0.1 accepts the given line without reporting an error.
>
> kind regards
>
> Tomas
>
>
>
>
>
>
>
> This message contains information that may be privileged or
> confidential and is the property of the Capgemini Group. It is intended
> only for the person to whom it is addressed. If you are not the
> intended recipient, you are not authorized to read, print, retain,
> copy, disseminate, distribute, or use this message or any part thereof.
> If you receive this message in error, please notify the sender
> immediately and delete all copies of this message.
>
>
> 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