caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Alex Baretta <alex@baretta.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: Lex and yacc
Date: Thu, 25 Jan 2001 11:14:36 +0100	[thread overview]
Message-ID: <20010125111436.B2338@miss.wu-wien.ac.at> (raw)
In-Reply-To: <002301c086a3$4fe3e320$68aa6ed4@alex>; from alex@baretta.com on Thu, Jan 25, 2001 at 08:49:12 +0100

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:

  http://miss.wu-wien.ac.at/~mottl/cpp_sources/reent.tar.gz

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



      reply	other threads:[~2001-01-26 21:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-25  7:49 Alex Baretta
2001-01-25 10:14 ` Markus Mottl [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=20010125111436.B2338@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=alex@baretta.com \
    --cc=caml-list@inria.fr \
    /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).