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=1.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, SPF_NEUTRAL 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 E98F3BBAF for ; Thu, 12 Mar 2009 12:31:57 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmQGANuOuEnVBJXyY2dsb2JhbACBTpNhFwgLBxG9BIQNBg X-IronPort-AV: E=Sophos;i="4.38,350,1233529200"; d="scan'208";a="24223632" Received: from outmailhost.telefonica.net (HELO ctsmtpout2.frontal.correo) ([213.4.149.242]) by mail3-smtp-sop.national.inria.fr with ESMTP; 12 Mar 2009 12:31:57 +0100 Received: from NANA.localdomain (83.54.185.214) by ctsmtpout2.frontal.correo (7.2.056.6) (authenticated as ferferse$telefonica.net) id 49B4D71300136210 for caml-list@inria.fr; Thu, 12 Mar 2009 12:31:51 +0100 Received: from mfp by NANA.localdomain with local (Exim 4.69) (envelope-from ) id 1Lhj8g-0004pj-3U for caml-list@inria.fr; Thu, 12 Mar 2009 12:31:50 +0100 Date: Thu, 12 Mar 2009 12:31:49 +0100 From: Mauricio Fernandez To: caml-list@inria.fr Subject: Re: [Caml-list] camlp4: precedence, LEFTA, NONA, etc. Message-ID: <20090312113149.GL8986@NANA.localdomain> Mail-Followup-To: caml-list@inria.fr References: <20BA0B67-42DD-4E9F-9165-741D91ECCF44@gmail.com> <527cf6bc0903120213k731ee9f5xb6b1104f12f001b@mail.gmail.com> <30261F42-54CA-4D16-9866-25A3E2646FAD@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30261F42-54CA-4D16-9866-25A3E2646FAD@gmail.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Spam: no; 0.00; camlp:01 camlp:01 expr:01 expr:01 2009:98 'and':98 wrote:01 precedence:01 precedence:01 caml-list:01 jambon:01 grammar:02 define:02 defined:02 lefta:02 On Thu, Mar 12, 2009 at 09:38:28AM +0000, Joel Reymont wrote: >> To my understanding, precendence levels correspond to the level you >> define in the grammar, in the given order : in your case, you have >> "=", "+" at the same level, with higher precendence than "And" and >> "*". > What about this quote from the camlp4 manual? > > "An entry is composed of entry precedence levels, the first one being > the least precedent and the last one the most." > > I'm assuming that my expr counts as one rule where '+' and '=' have > lesser precedence than 'and' and '*' since those follow after. In case of doubt, it's better to refer to Camlp4RevisedParser.ml, as said before (I don't even remember where the camlp4 manual is, I just open that file routinely when I'm about to do some camlp4 hacking :). In Camlp4RevisedParser.ml, expr is defined as: expr: [ "top" RIGHTA ... | "+" LEFTA [ e1 = SELF; op = infixop2; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] | "*" LEFTA ... | e1 = SELF; op = infixop3; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] (infixop3 is *, / or %) | "**" RIGHTA ... | "unary minus" NONA [ "-"; e = SELF -> mkumin _loc "-" e | "-."; e = SELF -> mkumin _loc "-." e ] So the levels are indeed listed in increasing order of precedence. This might be of use, despite being for camlp4 pre-3.10: http://martin.jambon.free.fr/extend-ocaml-syntax.html#priorities -- Mauricio Fernandez - http://eigenclass.org