Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <xleroy@pauillac.inria.fr>
To: bravier@dassault-aviation.fr (Thierry Bravier)
Cc: caml-list@pauillac.inria.fr
Subject: Re: re-entrance of ocamlyacc parsers
Date: Thu, 12 Jun 1997 16:39:00 +0200 (MET DST)	[thread overview]
Message-ID: <199706121439.QAA02070@pauillac.inria.fr> (raw)
In-Reply-To: <339513AC.4B89@dassault-aviation.fr> from Thierry Bravier at "Jun 4, 97 09:05:16 am"

> 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





  parent reply	other threads:[~1997-06-12 18:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-04  7:05 Thierry Bravier
1997-06-06 11:48 ` Thierry Bravier
1997-06-12 14:39 ` Xavier Leroy [this message]
1997-06-04 18:57 David Gurr

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=199706121439.QAA02070@pauillac.inria.fr \
    --to=xleroy@pauillac.inria.fr \
    --cc=bravier@dassault-aviation.fr \
    --cc=caml-list@pauillac.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