Is it possible to get AST for OCaml?

I would like to get AST for this OCaml program (I would like to go through AST and create, for example, an instrumental version of the code or do some kind of conversion). Does any OCaml tool support this functionality?

+5
source share
4 answers

camlp4 is the way to go. Here is an example of motivation. Documents are allowed - true, but you can read it through the wiki, existing examples, tutorials, and possibly even camlp4 sources.

+4
source

, , - [camlp4] [1]. camlp4, . , camlp5 [http://pauillac.inria.fr/~ddr/camlp5/], , wikipedia, , camlp4.

+2

OCaml 4.02.1 PPX, bu Alain Frisch, . :

% ocamlfind ppx_tools/dumpast -e "1 + 2"
1 + 2
==>
{pexp_desc =
  Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident "+"}},
   [("", {pexp_desc = Pexp_constant (Const_int 1)});
    ("", {pexp_desc = Pexp_constant (Const_int 2)})])}
=========

AST , . , , AST.

+1

compiler-libs . . Parsetree, Asttypes Ast_helper.

0

All Articles