Hi Jim, Yes, you are right, the "(expression)=>" predicate slows the parser down, the line i have posted stems from an earlier version of my grammar at a time i was experimenting with the possibilities of ANTLR. The final version of my grammar, which by the way describes a small SML like language to define UML Model Transformations, contains no seemingly awkward constructs .
But this is not my point here. The line in question is perfectly legal : there is no ambiguity. Therefore ANTLR should not report an error. Tomas ________________________________________ Von: [email protected] [[email protected]] im Auftrag von Jim Idle [[email protected]] Gesendet: Donnerstag, 18. November 2010 18:23 An: [email protected] Betreff: Re: [antlr-interest] Ambiguous reference 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: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Sam Harwell > Sent: Thursday, November 18, 2010 8:33 AM > To: 'Prerovsky, Tomas'; [email protected] > 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: [email protected] > [mailto:[email protected]] On Behalf Of Prerovsky, Tomas > Sent: Thursday, November 18, 2010 9:50 AM > To: [email protected] > 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 List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address 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 -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
