I'd like to be able to get the AST for a given OCaml program (I'd like to walk the AST and generate an instrumented version of the code or do some kind of transformation, for example). Do any of the OCaml tools support this functionality?
+2
A:
What you're looking for is [camlp4][1]. I haven't used camlp4 before, so I can't attest to it's virtues as software. I have heard of people using camlp5 [http://pauillac.inria.fr/~ddr/camlp5/] which, according to wikipedia, has better documentation than the current version of camlp4.
Axle
2010-06-30 02:55:48
aneccodeal
2010-06-30 03:03:25
+3
A:
camlp4 is a way to go. Here is a motivating example. The docs are sparse - true, but one can make his way reading through wiki, existing examples, tutorials, and maybe even camlp4 sources.
ygrek
2010-06-30 07:22:30
Insert calls co Camlp4prof.count (read "arbitrary") function at the beginning of each parsed function definition passing name and location parameters.
ygrek
2010-06-30 16:32:35
An Active discussion on resources to learn camlp4: http://groups.google.com/group/fa.caml/browse_thread/thread/1751a2c308742ac3?hl=en
nlucaroni
2010-09-28 13:29:46