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] Documenting CamlP4 syntax extensions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] Documenting CamlP4 syntax extensions

On Sat, Mar 02, 2002 at 01:59:37PM +0400, Mitya Lomov wrote:

> The first step to that will be, I guess, some kind of
> tool that is able to extract plain grammar definitions
> (like BNF) from CamlP4 sources (just rules, without
> semantics).

The function Grammar.Entry.print prints the rules of a grammar
entry. For example, the code:
    Grammar.Entry.print Pcaml.expr
prints the rules for expressions.

You can try it in the toplevel (load "camlp4o.cma" for normal syntax
or "camlp4r.cma" for revised syntax, before) or write a little program
displaying the main entry rules (defined in module Pcaml).

For example, to display expressions and patterns, file "":
    Format.printf "@[<v 2>expr@ ";
    Grammar.Entry.print Pcaml.expr;
    Format.printf "@]@.";
    Format.printf "@[<v 2>patt@ ";
    Grammar.Entry.print Pcaml.patt;
    Format.printf "@]@.";

    ocamlc -pp camlp4r -I +camlp4 -c

Print expressions and patterns rules of normal syntax:
    camlp4o ./foo.cmo

And of revised syntax:
    camlp4r ./foo.cmo

Perhaps a complete program displaying all entries (by scanning the
main grammar entries "interf" and "implem") could be useful. It is
possible to scan entries using the (undocumented) module Gramext.
I can do that, if you want it.

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