From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA07524 for caml-red; Fri, 26 Jan 2001 22:02:03 +0100 (MET) 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 LAA32375 for ; Thu, 25 Jan 2001 11:14:38 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f0PAEcH15363 for ; Thu, 25 Jan 2001 11:14:38 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id LAA05112; Thu, 25 Jan 2001 11:14:36 +0100 (MET) Date: Thu, 25 Jan 2001 11:14:36 +0100 From: Markus Mottl To: Alex Baretta Cc: Ocaml Mailing List Subject: Re: Lex and yacc Message-ID: <20010125111436.B2338@miss.wu-wien.ac.at> References: <002301c086a3$4fe3e320$68aa6ed4@alex> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <002301c086a3$4fe3e320$68aa6ed4@alex>; from alex@baretta.com on Thu, Jan 25, 2001 at 08:49:12 +0100 Sender: weis@pauillac.inria.fr 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