Chapter 24 The compiler front-end

This chapter describes the OCaml front-end, which declares the abstractsyntax tree used by the compiler, provides a way to parse, printand pretty-print OCaml code, and ultimately allows to write abstractsyntax tree preprocessors invoked via the -ppx flag (see chapters 9and 12) and plugins invoked via the -plugin flag(see chapter 22).

It is important to note that the exported front-end interface follows the evolution of the OCaml language and implementation, and thus does not provide any backwards compatibility guarantees.

The front-end is a part of compiler-libs library.Programs that use the compiler-libs library should be built as follows:

  1. ocamlfind ocamlc other options -package compiler-libs.common other files
  2. ocamlfind ocamlopt other options -package compiler-libs.common other files

Use of the ocamlfind utility is recommended. However, if this is not possible, an alternative method may be used:

  1. ocamlc other options -I +compiler-libs ocamlcommon.cma other files
  2. ocamlopt other options -I +compiler-libs ocamlcommon.cmxa other files

For interactive use of the compiler-libs library, start ocaml andtype#load "compiler-libs/ocamlcommon.cma";;.