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 autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id ABA6BBC6B for ; Tue, 30 Oct 2007 15:20:20 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPraJkfAbSoIh2dsb2JhbACOYAIBCAop X-IronPort-AV: E=Sophos;i="4.21,347,1188770400"; d="scan'208";a="5282599" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail3-smtp-sop.national.inria.fr with ESMTP; 30 Oct 2007 15:20:20 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from einhorn.in-berlin.de (localhost [127.0.0.1]) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id l9UEKIxw031821 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 30 Oct 2007 15:20:18 +0100 Received: (from www-data@localhost) by einhorn.in-berlin.de (8.13.6/8.13.6/Submit) id l9UEKISd031819 for caml-list@yquem.inria.fr; Tue, 30 Oct 2007 15:20:18 +0100 X-Authentication-Warning: einhorn.in-berlin.de: www-data set sender to oliver@first.in-berlin.de using -f Received: from dslb-088-073-074-138.pools.arcor-ip.net (dslb-088-073-074-138.pools.arcor-ip.net [88.73.74.138]) by webmail.in-berlin.de (IMP) with HTTP for ; Tue, 30 Oct 2007 15:20:18 +0100 Message-ID: <1193754018.47273da2796f7@webmail.in-berlin.de> Date: Tue, 30 Oct 2007 15:20:18 +0100 From: Oliver Bandel 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> In-Reply-To: <6C4DFFEF-0A5E-496F-9468-56693FFA4DC2@cs.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Spam: no; 0.00; bandel:01 in-berlin:01 ocaml:01 parser:01 parser:01 interprets:01 angela:98 angela:98 wrote:01 oliver:01 oliver:01 precedence:01 precedence:01 caml-list:01 conflicts:01 Zitat von Angela Zhu : > Hi all, > > I have some problem with precedence declaration in OCaml parser. > If I what to say exponential(ATOB) is prior to *(STAR) and / (DIVIDE), > * and / are prior to +(PLUS) and -(MINUS), > I wrote the following in the parser: > > > /***** Precedence Rules *****/ > ... > %left PLUS MINUS > %left STAR DIVIDE > %left ATOB > ... > > But I still have the following problems: > (1) It appears that the parser > reads "test = 2^2 + 7;" as "test = 2^9" instead of "test = 4+7", which > would follow the conventional order of operations. > > (2)It also interprets "test = (1^2)/3 + 1;" as "test = (1 ^ 2 > / (3 + 1));" > > Can any one help me to see why it happens? Why the precedence rules > doesn't work? [...] Precedences also can be created by sophisticated organization of the grammar rules. So, if your grammar rules may have a contradictory meaning, then your parser works not as expected. In general I would use the precedence-declarations only, when you run into parser conflicts, if you don't use them. When developing a grammr, I would recommend, first to start with the grammar rules, and add precedence-/associatitivity- declarations, at the end, if really necessary. What is the rest of your mly-file? A complete example would be helpful. Ciao, Oliver