From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id D231CBC6B for ; Wed, 31 Oct 2007 15:40:50 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAGgwKEeAKs4Fnmdsb2JhbACCcotyAgEBBwQGERg X-IronPort-AV: E=Sophos;i="4.21,351,1188770400"; d="scan'208,217";a="3881931" Received: from netscaler2.rice.edu (HELO mh2.mail.rice.edu) ([128.42.206.5]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 Oct 2007 15:40:36 +0100 Received: from mh2.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh2.mail.rice.edu (Postfix) with ESMTP id 659C81B4159; Wed, 31 Oct 2007 09:40:32 -0500 (CDT) X-Virus-Scanned: by amavis-2.4.4 at mh2.mail.rice.edu Received: from mh2.mail.rice.edu ([127.0.0.1]) by mh2.mail.rice.edu (mh2.mail.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MVp-nRLBUIOK; Wed, 31 Oct 2007 09:40:32 -0500 (CDT) Received: from [10.194.94.87] (unknown [10.194.94.87]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mh2.mail.rice.edu (Postfix) with ESMTP id 1A94D1B419F; Wed, 31 Oct 2007 09:40:30 -0500 (CDT) In-Reply-To: <47288DE3.3000603@irisa.fr> References: <6C4DFFEF-0A5E-496F-9468-56693FFA4DC2@cs.rice.edu> <1193753915.47273d3bb15f2@webmail.in-berlin.de> <23EC0ABA-12EE-49DE-B76A-1D91BCCAE1BA@cs.rice.edu> <21DAF2E3-1E29-476D-BEB3-FD608EBD92A2@cs.rice.edu> <47288DE3.3000603@irisa.fr> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: multipart/alternative; boundary=Apple-Mail-71-786061259 Message-Id: <11C06B30-EA78-40BB-984F-B403DC9BAE68@cs.rice.edu> Cc: caml-list@yquem.inria.fr From: Angela Zhu Subject: Re: [Caml-list] Problem with precedence declaration in .mly file Date: Wed, 31 Oct 2007 09:40:25 -0500 To: Thomas Gazagnaire X-Mailer: Apple Mail (2.752.3) X-Spam: no; 0.00; prec:01 expr:01 expr:01 cheers:01 ocamlyacc:01 ocamlyacc:01 syntax:01 beginner's:01 ocaml:01 bug:01 beginner's:01 ocaml:01 bug:01 prec:01 cheers:01 --Apple-Mail-71-786061259 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed But here are all the precedence rules I have: /***** Precedence Rules *****/ %left GT LT %left PLUS MINUS %left STAR DIVIDE %left ATOB %nonassoc prec_unary_minus -Angela On Oct 31, 2007, at 9:14 AM, Thomas Gazagnaire wrote: > The following code works perfectly for me. Maybe you introduce some =20= > undesired precedence rules in your grammar rules. > > > ---- > > %token INT > %token PLUS MINUS DIVIDE STAR ATOB END > > %start main > %type main > > %left PLUS MINUS > %left STAR DIVIDE > %left ATOB > > %% > > > main: > | expr END { $1 } > > expr: > | INT { $1 } > | expr PLUS expr { $1 + $3 } > | expr MINUS expr { $1 - $3 } > | expr DIVIDE expr { $1 / $3 } > | expr STAR expr { $1 * $3 } > | expr ATOB expr { int_of_float ( (float_of_int $1) ** =20 > (float_of_int $3) ) } > ; > > --- > > And then "2^2+7\n" gives me "11" > > Cheers, > Thomas > > Angela Zhu a =E9crit : >> On Oct 31, 2007, at 6:52 AM, Peter Ilberg wrote: >>> >>> I have no experience with ocamlyacc, but looking at your grammar =20 >>> below, it seems that you don't need the 'value PLUS exp' etc =20 >>> rules. All these cases should be covered already by the 'exp PLUS =20= >>> exp' rules at the beginning and the 'value' rule at the end. >>> >>> Try removing the 'value PLUS exp' rules. Maybe ocamlyacc gets =20 >>> confused if it has two sets of productions that it has to =20 >>> disambiguate with precedence rules. >> I removed 'value PLUS exp' rules. >> The precedence is still not correct, what is more, 1+ t (with t =20 >> declared) gives a syntax error. >> Thanks, >> Angela >>> >>> --- Peter >> _______________________________________________ >> Caml-list mailing list. Subscription management: >> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >> Archives: http://caml.inria.fr >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --Apple-Mail-71-786061259 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=ISO-8859-1 But here are=A0 all the = precedence rules I have:

/***** Precedence = Rules=A0= *****/
%left GT = LT
%left PLUS MINUS =A0
%left STAR DIVIDE = =A0
%left = ATOB
%nonassoc = prec_unary_minus


-Angela


On Oct 31, = 2007, at 9:14 AM, Thomas Gazagnaire wrote:

The following code works perfectly for me. Maybe you = introduce some undesired precedence rules in your grammar = rules.



%token <int> INT
%token = PLUS MINUS DIVIDE STAR ATOB END

%start main
%type <int> main

%left PLUS = MINUS
%left STAR DIVIDE
%left ATOB

%%


main:
| expr END { $1 }

| INT { $1 }
| expr PLUS expr { $1 + $3 }
| expr MINUS expr { $1 - $3 }
| expr DIVIDE expr { $1 / $3 }
| expr STAR expr { $1 * $3 }
| expr ATOB expr { int_of_float ( (float_of_int $1) = ** (float_of_int $3) ) }
;


And then "2^2+7\n" gives me "11"

Thomas

Angela = Zhu a =E9crit :
On Oct = 31, 2007, at 6:52 AM, Peter Ilberg wrote:

I have no experience with ocamlyacc, but looking at = your grammar below, it seems that you don't need the 'value PLUS exp' = etc rules. All these cases should be covered already by the 'exp PLUS = exp' rules at the beginning and the 'value' rule at the end.

Try = removing the 'value PLUS exp' rules. Maybe ocamlyacc gets confused if it = has two sets of productions that it has to disambiguate with precedence = rules.
I removed 'value PLUS exp' = rules.
The precedence is still not = correct, what is more, 1+ t (with t declared) gives a syntax = error.
Thanks,
Angela

--- = Peter
Caml-list mailing list. Subscription = management:
Caml-list mailing list. Subscription = management:

=

= --Apple-Mail-71-786061259--