caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mauricio Fernandez <mfp@acm.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] camlp4: precedence, LEFTA, NONA, etc.
Date: Thu, 12 Mar 2009 12:31:49 +0100	[thread overview]
Message-ID: <20090312113149.GL8986@NANA.localdomain> (raw)
In-Reply-To: <30261F42-54CA-4D16-9866-25A3E2646FAD@gmail.com>

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


      reply	other threads:[~2009-03-12 11:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-11 23:46 Joel Reymont
2009-03-12  9:13 ` [Caml-list] " blue storm
2009-03-12  9:20   ` Joel Reymont
2009-03-12  9:38   ` Joel Reymont
2009-03-12 11:31     ` Mauricio Fernandez [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090312113149.GL8986@NANA.localdomain \
    --to=mfp@acm.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).