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=none 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 88DA6BC6B for ; Wed, 31 Oct 2007 15:14:21 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.21,351,1188770400"; d="scan'208";a="3880677" Received: from bellamela.irisa.fr ([131.254.11.146]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 31 Oct 2007 15:14:21 +0100 Message-ID: <47288DE3.3000603@irisa.fr> Date: Wed, 31 Oct 2007 15:14:59 +0100 From: Thomas Gazagnaire User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Problem with precedence declaration in .mly file 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> In-Reply-To: <21DAF2E3-1E29-476D-BEB3-FD608EBD92A2@cs.rice.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; irisa:01 expr:01 expr:01 cheers:01 ocamlyacc:01 ocamlyacc:01 syntax:01 beginner's:01 ocaml:01 bug:01 angela:98 2007,:98 angela:98 beginners:01 token:01 The following code works perfectly for me. Maybe you introduce some 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) ** (float_of_int $3) ) } ; --- And then "2^2+7\n" gives me "11" Cheers, Thomas Angela Zhu a écrit : > > 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: > 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