Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
printing the AST of a caml function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-03-22 (16:24)
From: Zorg 421 <zorglub421@g...>
Subject: printing the AST of a caml function

I want to play/understand the caml AST, so I try using this code snippet:

let factstring = "let rec fact n = if n < 1 then 0 else n * fact (n-1)" in
let tree = Parse.implementation (Lexing.from_string factstring) in
Printast.implementation (Format.formatter_of_out_channel stdout) tree

and this build script (~15 minutes spent in ordering correctly the .cmx :-/ )

ocamlopt -I /opt/godi/lib/ocaml/compiler-lib/ misc.cmx linenum.cmx
warnings.cmx location.cmx lexer.cmx syntaxerr.cmx config.cmx
clflags.cmx parser.cmx parse.cmx printast.cmx lexing.cmx format.cmx -o factast

But the linker is confused by the Lexing module of stdlib:

Files /opt/godi/lib/ocaml/std-lib/lexing.cmx
and /opt/godi/lib/ocaml/std-lib/stdlib.cmxa both define a module named Lexing

How can I prevent the linker to look in /opt/godi/lib/ocaml/std-lib/
or /opt/godi/lib/ocaml/std-lib/stdlib.cmxa ?