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
Camlp4 as a universal pre-processor ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] Camlp4 as a universal pre-processor ?
Excerpts from David Teller's message of Tue Oct 23 07:54:33 +0200 2007:
>     Hello list,
>  I'm currently playing with camlp4 3.10. I've succeeded in making a
> syntax extension to help me generate annotated trees, which is a good
> start.
>  Now, I understand that, by invoking ocpp, camlp4 may be used as a
> pre-processor for non-OCaml language, which sounds interesting, for I
> have need of pre-processing some parser generator input (at the moment,
> menhir, but there are good chances I'll switch to Dypgen to get around
> some limitations) to maintain consistency between the implementation and
> the specifications. There are very good chances that I could do that
> with cpp, as it's essentially trivial pre-processing, but I'd rather use
> camlp4, if only to learn more about it.
>  So, my question is: how do I write a pre-processor that doesn't depend
> on the syntax of OCaml ? I'm hoping I can get away with one or two
> quotations and one anti-quotation, but I have no clue how to register
> these without adding dependencies to either OCaml's Original or Revised
> syntax. Does anyone have any examples handy ?

A  way  to  start  this  is  to  just keep the lexer and provide a new grammar
including  quotations  [2] and antiquotations. On the wiki [1] there is also a
small  but  complete example of a grammar for the untyped lambda calculus with
antiquotations [3], and also a tutorial of making a full parser with Camlp4 [4].

Nicolas Pouillard aka Ertai