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 PAA01899; Mon, 2 Sep 2002 15:59:51 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 PAA02047 for ; Mon, 2 Sep 2002 15:59:50 +0200 (MET DST) Received: from mel-rto2.wanadoo.fr (smtp-out-2.wanadoo.fr [193.252.19.254]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g82DxnD22925 for ; Mon, 2 Sep 2002 15:59:49 +0200 (MET DST) Received: from mel-rta8.wanadoo.fr (193.252.19.79) by mel-rto2.wanadoo.fr (6.5.007) id 3D5392B600A05A69; Mon, 2 Sep 2002 15:59:41 +0200 Received: from debian (80.8.82.91) by mel-rta8.wanadoo.fr (6.5.007) id 3D6EE81B0017D106; Mon, 2 Sep 2002 15:59:41 +0200 Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 17lrk3-0001t2-00; Mon, 02 Sep 2002 15:59:47 +0200 To: Oliver Bandel Cc: Remi VANICAT , caml-list@inria.fr Subject: Re: [Caml-list] Genlex - and which parser? References: From: Remi VANICAT Date: Mon, 02 Sep 2002 15:59:46 +0200 In-Reply-To: (Oliver Bandel's message of "Mon, 2 Sep 2002 14:35:32 +0200 (MET DST)") Message-ID: <871y8cqyp9.dlv@wanadoo.fr> User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-debian-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oliver Bandel writes: > Hello Rémi, > > > On Mon, 2 Sep 2002, Remi VANICAT wrote: > >> Oliver Bandel writes: > [...] >> > Which parser can be used together with Genlex? >> > Is it ocamlyacc? Or others? >> >> ocamlyacc goes with ocamllex. parser that goes with Genlex are stream >> parser, describe in chapter 2 of the Camlp4 reference manual and >> chapter 2 of the Camlp4 tutorial > > Hmhhh in the campl4-tutorial/-reference they explain an other > Lexer (Plexer). I think it's similar. > Will Genlex not be used? Or is Plexer based on Genlex? > > Any way, thanks for your hint. Well, there is to type of parser that you can read about in the camlp4 documentation : those of the chapter 2 (Streams and parsers) which correspond to the Genlex lexer, and those of the Camlp4 Grammar module, which use Plexer. Here an example of the Stream parser : open Genlex;; let lexer = make_lexer ["+"; "-"; "("; ")"];; let rec simple_calc = parser | [< v = simple_value ; rest >] -> simple_calc_rest v rest and simple_value = parser | [< 'Int i >] -> i | [< 'Kwd "("; v = simple_calc; 'Kwd ")" >] -> v and simple_calc_rest v1 = parser | [< 'Kwd "+"; v2 = simple_calc >] -> v1 + v2 | [< 'Kwd "-"; v2 = simple_calc >] -> v1 - v2 | [< >] -> v1;; let make_calc () = let l = read_line () in let st = Stream.of_string l in let le = lexer st in simple_calc le;; (notice that this parser is buggy : it evaluated 3 - 1 + 3 as -1 when it should answer 5). -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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