Browse thread
Functors and sharing a symbol table between a Menhir parser and ocamllex lexer
- Joel Reymont
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Joel Reymont <joelr1@g...> |
| Subject: | Functors and sharing a symbol table between a Menhir parser and ocamllex lexer |
I want to pass a symbol table to my Menhir parser since I want to run
several parsers in parallel and don't want any shared state.
I have this in the header of my ocamllex lexer:
module P = EasyParser.Make
(
struct
type t = EasySymtab.symtab_t
let putsym = EasySymtab.putsym
let infer_type = EasyCheck.infer_type
let symtype = EasyCheck.symtype
end
)
rule token tab = parse
...
Above are functions that take a symbol table as their first argument
and the lexer (token) takes the symbol table as well.
In my parser test harness I have:
let parse str =
let lexbuf = Lexing.from_string str in
let ast = EasyLexer.P.program (EasyLexer.token (symtab ())) lexbuf in
List.map EasyLocStrip.strip_stmt ast
How do I ensure that the lexer and the parser use the same symbol table?
I thought I could parameterize the parser on curried functions like
"putsym tab" but then how do I make sure that all functions in Make
above take the same tab?
If that works than I need to ensure that EasyLexer.token in my parse
function takes the same tab that was used by EasyParser.Make.
Any suggestions?
Thanks, Joel
--
http://wagerlabs.com/