Version française
Home     About     Download     Resources     Contact us    
Browse thread
There's an elephant in the room: Solution to sharing a symbol table
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Re: [Menhir-list] There's an elephant in the room: Solution to sharing a symbol table
On Wed, 2007-05-02 at 13:56 +0200, Francois Pottier wrote:
> Hello,
> 
> On Wed, May 02, 2007 at 07:04:50PM +1000, skaller wrote:
> > You can't. Don't be confused by functor interface in Menhir. 
> > It is useless for maintaining state.
> 
> I don't think so...

State must be maintained in function arguments.

Functors are entirely irrelevant. This is about associating
data with a thread of control.

Joel asked:

"How do you write parse above with the %parameter approach to ensure  
that parse ALWAYS uses a new symbol table that is shared between the  
lexer and the parser in this parsing run?"

and the answer is you have to pass an argument to the parser function.

> > What you need is a feature I asked for .. the possibility of
> > passing a state argument to the parser the same way you can
> > now do for ocamllex: you just write
> > 
> > 	rule fred state = parse ...
> 
> I remember our discussion. What you need primarily, if I recall
> correctly, is the ability for a semantic action to recursively
> invoke the parser itself. This happens to work if the parser is
> defined as a recursive function, and does not (currently) work
> when the parser is defined as a functor, because the functor is
> not declared as recursive. We could, in principle, make it a
> recursive functor, which would allow recursive invocations.

Let me give you a real example: I have a parser that
reads Felix code that looks like:

fun f .. // felix stuff
include "filename";
fun g .. //


When the parser sees the include statement it parses the
file 'filename'. The parse of the included file, in Felix,
is independent of the surrounding code. The parser is
called recursively and the resulting AST is returned
from the user action.

There is no way to do this without passing a state variable
on the stack. In fact Felix uses a variable passed to the
lexer to work around the deficiency in Ocamlyacc .. it
passes the variable to the parser in a token .. :)

[That works with Menhir too by the way]

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net