Hi,
On Mon, Aug 20, 2007 at 10:22:17AM +0200, Loup Vaillant wrote:
> This may be a better approach. However, I am not eager to use camlp*,
> for it will introduce a additional dependency. I may choose this
> however, if the camlp* AST is simpler than the Ocaml AST. Where can I
> find it?
Solution using camlp5:
For the syntax tree, look at:
http://pauillac.inria.fr/~ddr/camlp5/doc/html/ml_ast.html
You can generate abstract syntax tree by using concrete syntax. For
example, the syntax tree for the "if" statement is (in revised syntax):
MLast.ExIfe loc e1 e2 e3
but you can write it with quotations (in revised syntax):
<:expr< if $e1$ then $e2$ else $e3$ >>
and build syntax trees as complicated as you want using quotations.
But, well, you need to know camlp5, understand the quotation system,
perhaps the revised syntax too, in one word, read the doc, and I can
understand that if you did not use camlp5 before, it is some work...
Solution using camlp4:
The principle is the same but the syntax tree is different.
Other solution not using camlp*:
Read the ocaml sources, file "parsing/parser.mly" to understand how
the ocaml syntax tree works. Program your parser to generate this
syntax tree. Once done, to give your syntax tree directly to the
ocaml compiler, output:
1/ the magic number you can find in ocaml sources at utils/config.ml
- ast_impl_magic_number for an implementation
ast_intf_magic_number for an interface
2/ your input file name
3/ your syntax tree in binary with "output_value"
--
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/