From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA27274; Sat, 20 Sep 2003 21:07:51 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA07831 for ; Sat, 20 Sep 2003 21:07:50 +0200 (MET DST) Received: from rabelais.socialtools.net (rabelais.socialtools.net [81.2.94.243]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8KJ7nH04666 for ; Sat, 20 Sep 2003 21:07:49 +0200 (MET DST) Received: by rabelais.socialtools.net (Postfix, from userid 108) id A4630232DF; Sat, 20 Sep 2003 20:07:48 +0100 (BST) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id B92C0232DA; Sat, 20 Sep 2003 20:07:47 +0100 (BST) Message-ID: <3F6CA583.6050801@socialtools.net> Date: Sat, 20 Sep 2003 20:07:47 +0100 From: Benjamin Geer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-gb, en, fr, it MIME-Version: 1.0 To: Michal Moskal Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] parsing included files recursively using ocamllex and ocamlyacc References: <3F6C665E.5030508@socialtools.net> <20030920151541.GB4171@roke.freak> In-Reply-To: <20030920151541.GB4171@roke.freak> X-Enigmail-Version: 0.76.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-2.0 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, RCVD_IN_OSIRUSOFT_COM,REFERENCES,REPLY_WITH_QUOTES, USER_AGENT_MOZILLA_UA,X_ACCEPT_LANG version=2.54 X-Spam-Checker-Version: SpamAssassin 2.54 (1.174.2.17-2003-05-11-exp) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 recursively:01 michal:01 moskal:01 recursively:01 caml-list:01 becuase:01 filenames:01 run-time:01 c-like:01 lineno:01 recursion:01 caml:01 caml:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michal Moskal wrote: > On Sat, Sep 20, 2003 at 03:38:22PM +0100, Benjamin Geer wrote: >>I'm writing an interpreter for a small language (to be released as an >>open source library), using ocamllex and ocamlyacc. I'd like this >>language to support an instruction that, at compile time, recursively >>includes source code from another file. >> >>I searched the list archives and found a message >>(http://pauillac.inria.fr/caml/caml-list/0258.html) [snip] > > Wouldn't it work to simply call parsing function from parser rule? Well, the message mentioned above gave me the impression that it wouldn't be quite so easy, apparently becuase the generated parsing function isn't defined with "let rec". So I just wondered: has anyone done this? >>I considered using (or writing) a preprocessor to do the includes, but I >>couldn't think of a way to do this without losing the ability to report >>filenames and line numbers in run-time error messages. > > Maybe you should consider C-like: > > # lineno "filename" > > Then you could simply use cpp. I'd like not to have to depend on cpp, because this interpreter is for a specialised scripting language meant to be embedded in Caml programs. If those Caml programs had to spawn a process to run cpp before loading a script, that would probably be seen as too much overhead. I also want to make things as easy as possible for people who write scripts, so I don't want them to have to run cpp themselves. I just thought of another approach, which wouldn't use recursion in the parser. Each time the parser gets to an 'include filename' statement, it can store the filename in a list, and put a the filename in a node in the parse tree. After parsing a file, a function can parse (and cache) any files named in that list, and repeat until the list is empty. When the interpreter runs a program and finds a reference to an included file, it can get that file's parse tree from the cache. Ben ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners