Version française
Home     About     Download     Resources     Contact us    
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
Hi,

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 "foo.ml":
    Format.printf "@[<v 2>expr@ ";
    Grammar.Entry.print Pcaml.expr;
    Format.printf "@]@.";
    Format.printf "@[<v 2>patt@ ";
    Grammar.Entry.print Pcaml.patt;
    Format.printf "@]@.";

Compilation:
    ocamlc -pp camlp4r -I +camlp4 -c foo.ml

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.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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