English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2002-05-28 (18:48)
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";;

      [ "1" LEFTA [] | "2" LEFTA []];

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

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?


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

>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.
>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