caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Camlp4 as a universal pre-processor ?
@ 2007-10-23  5:54 David Teller
  2007-10-23  9:39 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 4+ messages in thread
From: David Teller @ 2007-10-23  5:54 UTC (permalink / raw)
  To: OCaml

    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 ?

Thanks,
 David

-- 
David Teller ------------------------------------------
Security of Distributed Systems -----------------------
Project JStify: Static Analysis for JavaScript 2  -----
-- http://www.univ-orleans.fr/lifo/Members/David.Teller
----- Laboratoire d'Informatique Fondamentale d'Orleans


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Camlp4 as a universal pre-processor ?
  2007-10-23  5:54 Camlp4 as a universal pre-processor ? David Teller
@ 2007-10-23  9:39 ` Nicolas Pouillard
  2007-10-23 10:34   ` David Teller
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Pouillard @ 2007-10-23  9:39 UTC (permalink / raw)
  To: David Teller; +Cc: caml-list

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].

[1]: http://brion.inria.fr/gallium/index.php/Camlp4
[2]: http://brion.inria.fr/gallium/index.php/Quotation
[3]: http://brion.inria.fr/gallium/index.php/Lambda_calculus_quotations
[4]: http://brion.inria.fr/gallium/index.php/Full_parser_tutorial
-- 
Nicolas Pouillard aka Ertai


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Camlp4 as a universal pre-processor ?
  2007-10-23  9:39 ` [Caml-list] " Nicolas Pouillard
@ 2007-10-23 10:34   ` David Teller
  2007-10-24 13:23     ` Nicolas Pouillard
  0 siblings, 1 reply; 4+ messages in thread
From: David Teller @ 2007-10-23 10:34 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

I've read the Lambda example, but it looked to me like it was a syntax
extension for OCaml and no other language, unless I completely
misunderstand the meaning of, say, <:expr<...>> .

Now, do you suggest I should write a full lexer and parser with Camlp4
just in order to write simple macros ?

Cheers,
 David

On Tue, 2007-10-23 at 11:39 +0200, Nicolas Pouillard wrote:
> 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].
> 
> [1]: http://brion.inria.fr/gallium/index.php/Camlp4
> [2]: http://brion.inria.fr/gallium/index.php/Quotation
> [3]: http://brion.inria.fr/gallium/index.php/Lambda_calculus_quotations
> [4]: http://brion.inria.fr/gallium/index.php/Full_parser_tutorial
-- 
David Teller ------------------------------------------
Security of Distributed Systems -----------------------
Project JStify: Static Analysis for JavaScript 2  -----
-- http://www.univ-orleans.fr/lifo/Members/David.Teller
----- Laboratoire d'Informatique Fondamentale d'Orleans


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Camlp4 as a universal pre-processor ?
  2007-10-23 10:34   ` David Teller
@ 2007-10-24 13:23     ` Nicolas Pouillard
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Pouillard @ 2007-10-24 13:23 UTC (permalink / raw)
  To: David Teller; +Cc: caml-list

Excerpts from David Teller's message of Tue Oct 23 12:34:15 +0200 2007:
> I've read the Lambda example, but it looked to me like it was a syntax
> extension for OCaml and no other language, unless I completely
> misunderstand the meaning of, say, <:expr<...>> .

You're  right the lambda example is not adapted.

> Now, do you suggest I should write a full lexer and parser with Camlp4
> just in order to write simple macros ?

Hum,  in  fact  that's  because  ocpp  is  no  longer supported in Camlp4 3.10
(another (external) tool that can replace it is in preparation).

However  writing  a  small  lexer  that catch some quotation of yours is quite
simple;  but  since  you  where talking about menhir and dypgen they certainly
have  lexing  conventions  quite  close  to OCaml, so the default lexer should
suffice.

It's  mainly  about writing a parser that search for some QUOTATION tokens and
expand them, in fact it will be even simpler to directly use a stream parser.

(* pseudo untested code *)
let rec go = parse
  | [< '(QUOTATION q, _loc); strm >] -> expand q; go strm
  | [< '(token, _loc); strm >] -> Token.<some function> tok; go strm
  | [< >] -> ()

> On Tue, 2007-10-23 at 11:39 +0200, Nicolas Pouillard wrote:
> > 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].
> > 
> > [1]: http://brion.inria.fr/gallium/index.php/Camlp4
> > [2]: http://brion.inria.fr/gallium/index.php/Quotation
> > [3]: http://brion.inria.fr/gallium/index.php/Lambda_calculus_quotations
> > [4]: http://brion.inria.fr/gallium/index.php/Full_parser_tutorial

-- 
Nicolas Pouillard aka Ertai


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-24 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-23  5:54 Camlp4 as a universal pre-processor ? David Teller
2007-10-23  9:39 ` [Caml-list] " Nicolas Pouillard
2007-10-23 10:34   ` David Teller
2007-10-24 13:23     ` Nicolas Pouillard

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).