yacc: how to fix ambiguity

"Lemaitre, Laurent" <r29173@email.sps.mot.com>
30 Oct 1998 13:57:39 -0500

          From comp.compilers

Related articles
yacc: how to fix ambiguity r29173@email.sps.mot.com (Lemaitre, Laurent) (1998-10-30)
Re: yacc: how to fix ambiguity rkrayhawk@aol.com (1998-11-01)
| List of all articles for this month |

From: "Lemaitre, Laurent" <r29173@email.sps.mot.com>
Newsgroups: comp.compilers
Date: 30 Oct 1998 13:57:39 -0500
Organization: Motorola
Keywords: yacc, question

Hi,


I am writing a parser for a specific grammar and
found the following problem for which I have no answer:


In my grammar expr and func are defined as:


expr := expr + expr
                | ( expr )
                | IDENTIFIER


func := IDENTIFIER IDENTIFIER ( IDENTIFIER )


define -> DEFINE func expr
                    | DEFINE IDENTIFER expr


The grammar is ambiguous. For instance:


ID ( ID ) + ID yields (a) FUNC expr
                                            (b) ID expr + expr


/*
for instance if I parse "define sign (x) +y" I
would like to mean sign(x) = +y and not sign = (x)+y
*/


I would like to tell yacc to reduce rule (a).


Is-it possible to code it into yacc input?


Any help/advice welcome,


Laurent


--
Laurent Lemaitre
ASTL/Advanced Circuit Research Lab - Europe Tel: +41 22 799 1371
Motorola Semiconductor Products Sector Fax: +41 22 799 1304
Geneva, Switzerland r29173@email.sps.mot.com


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.