caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benjamin Geer <ben@socialtools.net>
To: Michal Moskal <malekith@pld-linux.org>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] parsing included files recursively using ocamllex and ocamlyacc
Date: Sat, 20 Sep 2003 20:07:47 +0100	[thread overview]
Message-ID: <3F6CA583.6050801@socialtools.net> (raw)
In-Reply-To: <20030920151541.GB4171@roke.freak>

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


  reply	other threads:[~2003-09-20 19:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-20 14:38 Benjamin Geer
2003-09-20 15:15 ` Michal Moskal
2003-09-20 19:07   ` Benjamin Geer [this message]
2003-09-22  7:22     ` Eckart Goehler
2003-09-22  8:41 ` Hendrik Tews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F6CA583.6050801@socialtools.net \
    --to=ben@socialtools.net \
    --cc=caml-list@inria.fr \
    --cc=malekith@pld-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).