English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    
Browse thread
[Caml-list] infix precedence
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: dengping zhu <zhudp@c...>
Subject: Re: [Caml-list] infix precedence

I tried camlp4 before. I got the example from the camlp4 tutorial and
modified a little bit. 

The code is as follows:
---------------------------------------------
let gram = Grammar.create (Plexer.make());;
let expr = Grammar.Entry.create gram "expr";;

EXTEND
  expr:
      [ "1" LEFTA [] | "2" LEFTA []];
END;;

let add_infix lev op =
         EXTEND
           GLOBAL: expr;
           expr: LEVEL $lev$
            [ [ x = expr; $op$; y = expr -> <:expr< $lid:op$ $x$ $y$ >> ] ];
         END;;
-------------------------------------------------------------------

After I compile it in ocaml 

# #use "foo.ml";;

I can use the function 'add_infix':
# add_infix "1" "op1";;

But how can I use the infix "op1" later? 
I tried to use as follows:

#let op1 x y = x + y;;
#Grammar.Entry.parse expr ( Stream.of_string "x op1 y");;

But I got an error. 

Can someboday pass an example for me?

Thanks!




On Tue, 28 May 2002, Daniel de Rauglaudre wrote:

>Hi,
>
>On Tue, May 28, 2002 at 02:16:12PM -0400, dengping zhu wrote:
>
>> Hi, John, thanks for your help.  Hope I could solve it today.
>> Anyway, I think that Ocaml should support infix as SML.
>
>Camlp4
>
>-- 
>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