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
Lex and yacc
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-01-26 (21:02)
From: Markus Mottl <mottl@m...>
Subject: Re: Lex and yacc
On Thu, 25 Jan 2001, Alex Baretta wrote:
> I have used ocamllex and ocamlyacc to write lexers and parsers for a
> few different variants of a lambda calculus, and I think they are
> excellent tools. Yesterday, I tried to take advantage of the
> experience I had by using Flex and Bison to write a lexer and parser
> for the http protocol to be used in a proxy to be written in C. I read
> the texinfo manual for both, and I have noticed that, while Bison
> takes care to generate reentrant parsers, flex *apparently* generates
> code that is inadequate on a multithreaded process with several open
> input streams and several parsers running contemporarily (but you may
> correct me if I am mistaken). I am pretty sure these problems do not
> exists in ocamllex and ocamlyacc. Now, can you gurus teach me a way to
> write my reentrant lexer and parser with the Ocaml tools and link the
> result with a C application? (I am not sure the professor would accept
> this solution, but if it feasible I might try to convince him... ;-)

You can, of course, use the OCaml-tools to get reentrant scanners/parsers,
but it is also possible (though a bit more cumbersome) using bison and
flex. To do this you only need to ask flex to generate C++-code. Then you
can use scanner classes, which maintain their own state (i.e. the channel
they are associated with and the current position in the input stream).

In another life, when I was still vainly trying to learn C++, I wrote
an example solution to this problem, which pops up quite frequently. You
can get it from here:


If there is any chance to convince your professor that you should use
OCaml rather than C/C++, do it ;)

- Markus Mottl

Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl