The compiler front-end

# Chapter 23 The compiler front-end

This chapter describes the OCaml front-end, which declares the abstract syntax tree used by the compiler, provides a way to parse, print and pretty-print OCaml code, and ultimately allows to write abstract syntax tree preprocessors invoked via the -ppx flag (see chapters 8 and 11).

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:

            ocamlfind ocamlc other options -package compiler-libs.common other files
            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:

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

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

- Module Ast_helper: helper functions for AST construction
- Module Ast_mapper: -ppx rewriter interface
- Module Asttypes: auxiliary types used by Parsetree
- Module Location: source code locations
- Module Longident: long identifiers
- Module Parse: OCaml syntax parsing
- Module Parsetree: OCaml syntax tree
- Module Pprintast: OCaml syntax printing