From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA29110; Wed, 29 May 2002 04:48:41 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA29068 for ; Wed, 29 May 2002 04:48:40 +0200 (MET DST) Received: from cs.bu.edu (cs.bu.edu [128.197.12.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g4T2mcT17853; Wed, 29 May 2002 04:48:38 +0200 (MET DST) Received: from csa.bu.edu (zhudp@csa [128.197.12.3]) by cs.bu.edu (8.12.2/8.12.2) with ESMTP id g4T2mcF2003060; Tue, 28 May 2002 22:48:38 -0400 (EDT) Received: from localhost (zhudp@localhost) by csa.bu.edu (8.10.1/8.10.1) with ESMTP id g4T2mXA12370; Tue, 28 May 2002 22:48:33 -0400 (EDT) X-Authentication-Warning: csa.bu.edu: zhudp owned process doing -bs Date: Tue, 28 May 2002 22:48:33 -0400 (EDT) From: dengping zhu X-Sender: zhudp@csa.bu.edu To: Daniel de Rauglaudre cc: Ocaml Subject: Re: [Caml-list] infix precedence In-Reply-To: <20020529004457.B1511@verdot.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = > >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 = > # 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