English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Passing a symbol table to the parser
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-04-27 (08:13)
From: Francois Pottier <Francois.Pottier@i...>
Subject: Re: [Menhir-list] Passing a symbol table to the parser


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

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