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 RAA25745; Sat, 20 Sep 2003 17:20:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA28213 for ; Sat, 20 Sep 2003 17:20:15 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8KFKD524456 for ; Sat, 20 Sep 2003 17:20:13 +0200 (MET DST) Received: (qmail 29842 invoked by uid 566); 20 Sep 2003 15:20:10 -0000 Date: Sat, 20 Sep 2003 17:15:42 +0200 From: Michal Moskal To: Benjamin Geer Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] parsing included files recursively using ocamllex and ocamlyacc Message-ID: <20030920151541.GB4171@roke.freak> Mail-Followup-To: Benjamin Geer , "caml-list@inria.fr" References: <3F6C665E.5030508@socialtools.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F6C665E.5030508@socialtools.net> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 recursively:01 recursively:01 caml-list:01 filenames:01 run-time:01 c-like:01 lineno:01 michal:01 moskal:01 malekith:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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), posted here in 1997 > by Xavier Leroy, which suggests one way to write a recursive > "yacc_start" function. However, the details of this approach aren't > clear to me; could someone provide a more detailed explanation of what > would be involved (e.g. a brief outline of the contents of this > function)? What about ocamllex? Would I have to save the lexbuf on a > stack, and restore it after each recursive call? Wouldn't it work to simply call parsing function from parser rule? > 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. Supporting it will also have the added benefit for peaople trying to genarete code in your language. -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- 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