Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] parsing included files recursively using ocamllex and ocamlyacc
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michal Moskal <malekith@p...>
Subject: Re: [Caml-list] parsing included files recursively using ocamllex and ocamlyacc
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 
> (, 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 :: : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: