From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id EF49FBC69 for ; Fri, 30 Mar 2007 15:30:09 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2UDU9ci025355 for ; Fri, 30 Mar 2007 15:30:09 +0200 Received: by ug-out-1314.google.com with SMTP id k3so884633ugf for ; Fri, 30 Mar 2007 06:30:09 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=erCZrAlc18fyMF2HgRf+qsP8tvv5wBvLxeDp+66UDPSyxKh+Y++RSG+AzrztqpIR6lgBMA0xdm+1mznJv9bqGaCqFduTTgbl2D9K3w/FetdQK9YuG6nlQW1RgrfwEVRCIDFc2B3sd0KvmkIt3g+aWkgHvUVQZFyiofrfM28NdS0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=TjSFxhLxvNv9d3wNNLPwVuyqctmwCsLf6q7TAZ/Bttl+GhndARgumW+LHppSGotznzzdmDbK5Q7CrdRxfm8TaAuRq1437mi2JLS6KyJvL+VEC7WdfWQvAmpMy1szm3Q4xWjnKbQcrStl7cPlhJ1cMuB2J0Qy+zqwyvzIiAq7TEg= Received: by 10.67.95.3 with SMTP id x3mr1989112ugl.1175261408875; Fri, 30 Mar 2007 06:30:08 -0700 (PDT) Received: from ?192.168.1.34? ( [88.7.143.102]) by mx.google.com with ESMTP id y34sm1346579iky.2007.03.30.06.30.05; Fri, 30 Mar 2007 06:30:07 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v752.3) Content-Transfer-Encoding: 7bit Message-Id: <7F1226C5-BB02-443B-8854-785642ADDE3C@gmail.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: Caml List From: Joel Reymont Subject: Hacking Parsing to be re-entrant Date: Fri, 30 Mar 2007 14:30:00 +0100 X-Mailer: Apple Mail (2.752.3) X-j-chkmail-Score: MSGID : 460D10E1.000 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 460D10E1.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; parsing:01 parsing:01 stack:01 stack:01 stacksize:01 parser:01 ocamlyacc:01 ocamlyacc:01 parser:01 lexing:01 lexbuf:01 lexbuf:01 lexing:01 char:01 token:01 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/