[antlr-interest] Ambiguous reference

Sam Harwell sharwell at pixelminegames.com
Thu Nov 18 08:32:48 PST 2010


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



More information about the antlr-interest mailing list