Clone this wiki locally
Warning: status of this documentation
This documentation tries to cover the latest version of Camlp4 (3.10) by explaining it from scratch and also by explaining differences with the previous version (3.09). This is a work in progress, so please feel free to contribute.
Here is a page that states the priorities of that documentation.
Camlp4 is a Pre-Processor-Pretty-Printer (this is what the "p4" part stands for) for the OCaml language.
Pre-processor: Camlp4 may be used as a Pre-Processor for the OCaml compiler; the parsing is done by Camlp4, and the OCaml compiler resumes the rest of the compilation.
Pretty-printer: Camlp4 can pretty print the normal OCaml concrete syntax or the revised one using a Pretty-Printer. It is therefore always possible to have a version of your sources compilable by the compiler OCaml without preprocessing.
Where to begin?
The using Camlp4 page describes how to use the various Camlp4 executables.
The OCaml code generation tutorial provides information on how to generate OCaml code in Camlp4.
The full parser tutorial explains how to use Camlp4 as a complete parser for a given grammar.
pa_float, a simple OCaml extension showing how to locally transform the AST.
This part should be reorganized
Camlp4 can parse normal OCaml concrete syntax or any other user-definable syntax. As an example, an alternative syntax is provided, named Revised, because it tries to fix some problems of the original syntax.
OCaml-independent parts of Camlp4
Camlp4 can be compared to parsers generators such as Yacc, OCamlYacc, Menhir, Dypgen...
The main source of documentation about theses parsers is: Extensible Parser.
However there are some related points.
- Dealing with Locations.
- Connecting your own Lexer.
- Handling Keywords.
It includes a Quotation system.