From: skaller <skaller@users.sourceforge.net>
To: Francois.Pottier@inria.fr
Cc: Caml List <caml-list@inria.fr>, menhir-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: [Menhir-list] There's an elephant in the room: Solution to sharing a symbol table
Date: Thu, 03 May 2007 11:17:52 +1000 [thread overview]
Message-ID: <1178155073.7026.14.camel@rosella.wigram> (raw)
In-Reply-To: <20070502183020.GA17473@yquem.inria.fr>
On Wed, 2007-05-02 at 20:30 +0200, Francois Pottier wrote:
> Hi,
>
> On Thu, May 03, 2007 at 02:07:26AM +1000, skaller wrote:
> > State must be maintained in function arguments.
>
> This is a trivial example, but:
>
> let x = ref 0
> let f () : bool = incr x; x / 2 = 0
Yes, but I rule out global mutable state as unacceptable
by requiring reentrancy.
> Here, f exploits an internal state, even though it is not explicitly
> parameterized over a piece of state. Similarly, a parser can have internal
> state, even if the parsing functions are not explicitly parameterized over a
> piece of state. It is sufficient for the entire parser either to refer to a
> global variable or to abstracted over a piece of state (which functors allow).
As above, if that state is global the result isn't re-entrant
and isn't acceptable.
> I don't see why this is so. In fact, nothing in your example seems to require
> any kind of state -- you only need the parser to be able to recursively invoke
> itself. Or am I missing something?
I didn't show the full parser of course. In fact, Felix grammar
is user extensible, so there has to be somewhere to hold
the extensions. Similarly, a C parser requires a symbol table
for typedefs, and Felix allows embedded C.
In fact, Felix can call the FrontC/CIL parser on fragments
of C code -- and CIL uses global variables so isn't re-entrant.
In fact Joel explained the 'elephant' technique:
let parser str =
let tab = .. in
let lexbuf = Lexing.from_string str in
let module P = EasyParser.Make (struct let tab = tab end) in
P.program (token tab) lexbuf
which uses a local module to turn a global variable into
a function local one. That's pretty clever, the function
'parser' here is reentrant (even though P.program is not).
To support recursion you'd need:
let module P = EasyParser.Make (struct
let tab = tab
let parser = parser (* pass fun for recursion *)
end) in
Quite a clever use of a local modules and functors therefore,
allows %parameter to suffice, without further changes to
Menhir .. though it would still be much easier if you
could just do it like Ocamllex, I have to agree this does
work.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2007-05-03 1:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 21:39 Joel Reymont
2007-05-02 5:44 ` [Menhir-list] " Francois Pottier
2007-05-02 5:58 ` Joel Reymont
[not found] ` <20070502070345.GA5242@yquem.inria.fr>
2007-05-02 7:35 ` Joel Reymont
2007-05-02 9:04 ` [Caml-list] " skaller
2007-05-02 11:56 ` Francois Pottier
2007-05-02 16:07 ` skaller
2007-05-02 18:30 ` Francois Pottier
2007-05-03 1:17 ` skaller [this message]
2007-05-03 8:48 ` Joel Reymont
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=1178155073.7026.14.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=Francois.Pottier@inria.fr \
--cc=caml-list@inria.fr \
--cc=menhir-list@yquem.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