Version française
Home     About     Download     Resources     Contact us    
Browse thread
Hacking Parsing to be re-entrant
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: Hacking Parsing to be re-entrant
Folks,

It seems that the global state in the Parsing module is confined to

let env =
   { s_stack = Array.create 100 0;
     v_stack = Array.create 100 (Obj.repr ());
     symb_start_stack = Array.create 100 dummy_pos;
     symb_end_stack = Array.create 100 dummy_pos;
     stacksize = 100;
     stackbase = 0;
     curr_char = 0;
     lval = Obj.repr ();
     symb_start = dummy_pos;
     symb_end = dummy_pos;
     asp = 0;
     rule_len = 0;
     rule_number = 0;
     sp = 0;
     state = 0;
     errflag = 0 }

To make a parser generated by ocamlyacc re-entrant one would need to  
pass env as argument to any function that uses it (a handful) as well  
as make ocamlyacc include it in the parser entry function together  
with yytables, etc.

let program (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
    (Parsing.yyparse yytables 1 lexfun lexbuf : Easy.program)

Am I missing something crucial here or is this an easy hack?

	Thanks, Joel

--
http://wagerlabs.com/