caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Lex and yacc
@ 2001-01-25  7:49 Alex Baretta
  2001-01-25 10:14 ` Markus Mottl
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Baretta @ 2001-01-25  7:49 UTC (permalink / raw)
  To: Ocaml Mailing List

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

Thanks for your time!

Alex



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Lex and yacc
  2001-01-25  7:49 Lex and yacc Alex Baretta
@ 2001-01-25 10:14 ` Markus Mottl
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Mottl @ 2001-01-25 10:14 UTC (permalink / raw)
  To: Alex Baretta; +Cc: Ocaml Mailing List

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-01-26 21:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-25  7:49 Lex and yacc Alex Baretta
2001-01-25 10:14 ` Markus Mottl

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