Skip to content


Hsu Hung-Wei edited this page · 4 revisions


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?

Camlp4 in-depth

This part should be reorganized


It offers tools for syntax (Stream Parsers and Grammars) and the ability to modify the concrete syntax of the language (Quotations, Syntax extensions).

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.

Camlp4 can also serve as a Program Transformation tool, the user can supply transformations and apply them easily as a pre-processing task. This is done with Filters.

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.

Camlp4 is also OCaml oriented

Something went wrong with that request. Please try again.