caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: Oliver Bandel <oliver@first.in-berlin.de>
Cc: Remi VANICAT <vanicat@labri.u-bordeaux.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] Genlex - and which parser?
Date: Mon, 02 Sep 2002 15:59:46 +0200	[thread overview]
Message-ID: <871y8cqyp9.dlv@wanadoo.fr> (raw)
In-Reply-To: <Pine.LNX.3.95.1020902142532.128A-100000@first.in-berlin.de> (Oliver Bandel's message of "Mon, 2 Sep 2002 14:35:32 +0200 (MET DST)")

Oliver Bandel <oliver@first.in-berlin.de> writes:

> Hello Rémi,
>
>
> On Mon, 2 Sep 2002, Remi VANICAT wrote:
>
>> Oliver Bandel <oliver@first.in-berlin.de> 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


      parent reply	other threads:[~2002-09-02 13:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-01 16:53 Oliver Bandel
2002-09-01 22:18 ` Remi VANICAT
2002-09-02 12:35   ` Oliver Bandel
2002-09-02 13:53     ` Daniel de Rauglaudre
2002-09-02 13:59     ` Remi VANICAT [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=871y8cqyp9.dlv@wanadoo.fr \
    --to=vanicat@labri.u-bordeaux.fr \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    /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).