本章描述 OCaml 前端,其宣告編譯器使用的抽象語法樹,提供解析、列印和美化列印 OCaml 程式碼的方式,並最終允許使用者撰寫透過 -ppx 旗標調用的抽象語法樹前處理器(參見第 13 章和第 16 章)。
重要的是要注意,匯出的前端介面會隨著 OCaml 語言和實作的演進而變化,因此不提供任何向後相容性的保證。
前端是 compiler-libs 函式庫的一部分。使用 compiler-libs 函式庫的程式應按如下方式建置:
ocamlfind ocamlc other options -package compiler-libs.common other files ocamlfind ocamlopt other options -package compiler-libs.common other files
建議使用 ocamlfind 工具。但是,如果無法使用,則可以使用替代方法
ocamlc other options -I +compiler-libs ocamlcommon.cma other files ocamlopt other options -I +compiler-libs ocamlcommon.cmxa other files
若要互動式使用 compiler-libs 函式庫,請啟動 ocaml 並輸入
#load "compiler-libs/ocamlcommon.cma";;.