Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Passing a symbol table to the parser

2 views
Skip to first unread message

Joel Reymont

unread,
Apr 26, 2007, 4:50:14 AM4/26/07
to menhi...@yquem.inria.fr
Folks,

How would I pass a symbol table to a Menhir parser so that it's
available in my rules?

Thanks, Joel

--
http://wagerlabs.com/

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Francois Pottier

unread,
Apr 27, 2007, 4:15:04 AM4/27/07
to Joel Reymont

Hello,

On Thu, Apr 26, 2007 at 09:48:35AM +0100, Joel Reymont wrote:
> How would I pass a symbol table to a Menhir parser so that it's
> available in my rules?

The most basic solution is to make the symbol table mutable (e.g. make it a
hash table, or a mutable reference to a persistent data structure) and place
it in a global variable in some earlier module.

If, in addition, you need reentrancy and don't want your parser to depend on a
global variable, then you can move this global variable to a functor parameter,
using a %parameter declaration, like this:

%parameter <T : sig
type symbol
type info
val get: symbol -> info
val set: symbol -> info -> unit
end>

Then, your semantic actions can refer to T.get and T.set, and Menhir produces
a parser that is parameterized over T.

--
François Pottier
Francois...@inria.fr
http://cristal.inria.fr/~fpottier/

0 new messages