caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: dengping zhu <zhudp@cs.bu.edu>
To: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] infix precedence
Date: Fri, 21 Jun 2002 13:54:39 -0400 (EDT)	[thread overview]
Message-ID: <Pine.SOL.4.20.0206211334510.28082-100000@csa.bu.edu> (raw)
In-Reply-To: <Pine.SOL.4.20.0205282247140.28396-100000@csa.bu.edu>

Hi, Daniel, I have to raise some questions about infix declaration in
camlp4 again.

Now I defined some infix as follows:
------------------------------------
let add_infix lev op = 
  EXTEND
      GLOBAL: Pcaml.expr;
          Pcaml.expr: LEVEL $lev$    
	      [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$
	      >> ] ];   
	        END;; 

let _ = add_infix "*" ">>*"
let _ = add_infix "<" "wth"
let _ = add_infix "||" "|||"
------------------------------------

Then I have a following function:

  let f = number ||| literal '-' >>* number wth (fun x -> -x)

(where number and literal are some function I defined before.)

According to the infix definition above, this function should 
work as:

  let f = number ||| (literal '-' >>* number wth (fun x -> -x))

because the precedence of 'wth' is higher than that of '|||'.
But, it turns out to evaluate as:

  let f = (number ||| literal '-' >>* number) wth (fun x -> -x)

So, I have to add parenthesis so that it can work properly.
Can you help me to figure out this problem because I want to get rid of
the parenthesis so that my code is more readable? 

Thanks a lot!
Dengping


On Tue, 28 May 2002, dengping zhu wrote:

>Hi, Daniel, it works very well.
>Thanks a lot!
>
>Dengping
>
>
>
>
>On Wed, 29 May 2002, Daniel de Rauglaudre wrote:
>
>>Hi,
>>
>>On Tue, May 28, 2002 at 02:48:42PM -0400, dengping zhu wrote:
>>> 
>>> I tried camlp4 before. I got the example from the camlp4 tutorial and
>>> modified a little bit. 
>>
>>Your code cannot work: you are defining a new entry, you are not using
>>the entry of OCaml expressions, which is Pcaml.expr.
>>
>>  $ cat foo.ml
>>  let add_infix lev op =
>>  EXTEND
>>    GLOBAL: Pcaml.expr;
>>    Pcaml.expr: LEVEL $lev$
>>      [ [ x = SELF; $op$; y = SELF -> <:expr< $lid:op$ $x$ $y$ >> ] ];
>>  END;;
>>  $ ocaml
>>	  Objective Caml version 3.04+11 (2002-05-16)
>>  
>>  # #load "camlp4o.cma";;
>>	  Camlp4s Parsing version 3.04+11
>>  
>>  # #load "pa_extend.cmo";;    
>>  # #load "q_MLast.cmo";;  
>>  # #use "foo.ml";;
>>  val add_infix : string -> string -> unit = <fun>
>>
>>Type:
>>   Grammar.Entry.print Pcaml.expr;;
>>to see the current entry of expressions.
>>
>>The available levels are "top", "expr1", ":=", "||", "&&", "<", "^",
>>"+", "*", "**", "unary minus", "apply", "label", ".", "~-", "simple".
>>They are the one you can use as first parameter of add_infix:
>>
>>  # add_infix "*" "op1";;
>>
>>If you type
>>   Grammar.Entry.print Pcaml.expr;;
>>then you see that the rule with "op1" has been added in the level "*".
>>
>>  # let op1 x y = x + y + 1;;
>>  Toplevel input:
>>  # let op1 x y = x + y + 1;;
>>	^^^
>>  Parse error: 'module' uppercase identifier expected after 'let' (in
>>    [str_item])
>>
>>Normal, since "op1" is now a keyword. Mmmm... the normal form should be:
>>   let (op1) x y = x + y + 1;;
>>But it does not work... this is a bug in Camlp4 that I am going to fix.
>>
>>A solution should be to define it before the "add_infix"...
>>
>>But, in the meantime, this works:
>>   # let \op1 x y = x + y + 1;;
>>   val op1 : int -> int -> int = <fun>
>>   # 3 op1 4;;
>>   - : int = 8
>>
>>-- 
>>Daniel de RAUGLAUDRE
>>daniel.de_rauglaudre@inria.fr
>>http://cristal.inria.fr/~ddr/
>>-------------------
>>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>
>
>-------------------
>To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
>Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      parent reply	other threads:[~2002-06-21 17:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-28 15:42 dengping zhu
2002-05-28 15:54 ` Remi VANICAT
2002-05-28 16:00 ` John Prevost
2002-05-28 17:19   ` dengping zhu
2002-05-28 18:07     ` John Prevost
2002-05-28 18:16       ` dengping zhu
2002-05-28 18:32         ` Daniel de Rauglaudre
2002-05-28 18:48           ` dengping zhu
2002-05-28 22:44             ` Daniel de Rauglaudre
2002-05-29  2:48               ` dengping zhu
2002-05-29  8:42                 ` Daniel de Rauglaudre
2002-06-21 17:54                 ` dengping zhu [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=Pine.SOL.4.20.0206211334510.28082-100000@csa.bu.edu \
    --to=zhudp@cs.bu.edu \
    --cc=caml-list@inria.fr \
    --cc=daniel.de_rauglaudre@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).