Re: re-entrance of ocamlyacc parsers

From: Xavier Leroy (xleroy@pauillac.inria.fr)
Date: Thu Jun 12 1997 - 16:39:00 MET DST


From: Xavier Leroy <xleroy@pauillac.inria.fr>
Message-Id: <199706121439.QAA02070@pauillac.inria.fr>
Subject: Re: re-entrance of ocamlyacc parsers
In-Reply-To: <339513AC.4B89@dassault-aviation.fr> from Thierry Bravier at "Jun 4, 97 09:05:16 am"
To: bravier@dassault-aviation.fr (Thierry Bravier)
Date: Thu, 12 Jun 1997 16:39:00 +0200 (MET DST)

> I would like to be able to call the ocamlyacc-generated code
> recursively from an ocamlyacc semantic action.

> 1) I wonder how I can define a function `compile_file'
> that ends up calling `yacc_start' recursively.
>
> Maybe generating a function `yacc_start' defined with
> `let rec' instead of `let' would do (as with ocamllex).

The "let rec" would need to enclose not only the entry points, but
also the table of actions yyact, since that's where the recursive
calls occur.

A simple, if not very elegant solution, is to use a reference to a
function, initialized to a dummy function and later changed to
"yacc_start". (Same trick as for cross-module recursion, as described
at the end of the chapter on ocamlc in the manual.) It's definitely
less ugly than your perl script.

> 2) Anyway, I noticed that the ocamlyacc-generated code
> (see stdlib/parsing.ml) uses a global value `env' (which can
> be emptied with `clear_parser ()').
>
> Does this forbid `yacc_start' re-entrance ?
>
> I mean, will the inner call to `yacc_start' corrupt `env' value
> for the outer call to work properly ?
>
> Or can I just see `env' as an implementation issue not to
> be considered by module `Parsing' users ?

The module Parsing is supposed to be reentrant. Yes, there's some
global state inside, but we're careful to save and restore it across
entries. If you have a program demonstrating non-reentrance, please
send it to me privately and I'll try to fix that.

- Xavier Leroy



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:11 MET