From: mulhern <mulhern@cs.wisc.edu>
To: caml-list@yquem.inria.fr
Subject: How to get an AST of OCaml source?
Date: Wed, 23 Feb 2005 21:25:59 -0600 [thread overview]
Message-ID: <e81dbc44e27d0078e72d08361979e0fd@cs.wisc.edu> (raw)
Hi,
I need to use OCaml source code as input to a tool that generates a
related sort of output. It's not a source-to-source translator; the
code generated will not do what the OCaml source code does. It's not a
pretty printer either, the relationship isn't so direct. I'ld like to
write the tool itself in OCaml and am hoping to use CamlTemplate.
What is the most direct way to get a useful, easily traversable,
representation of OCaml source code in OCaml? Clearly, there is one
embedded in the various ocaml tools.
I understand that Camlp4 will dump out a binary AST, which is then
input to the OCaml compiler. If that is the best way to go, could
somebody give me some pointers about how to traverse this AST? I have
been unable to extract the information from the Camlp4 documentation.
I have also been looking at the OCaml src code distribution. I realize
it's possible to pass the compiler a flag (dparsetree) that will cause
a pretty-printed version of the parse tree to be dumped out. On
examination of compiler.ml I can see how that ast that gets pretty
printed is constructed. Is my best bet to write an ocaml application
that just uses a a large chunk of the ocamlc source code modeling the
application as best I can on the compiler.ml source?
Or would I be better off parsing the pretty-printed stuff that gets
dumped out? Or, could I write my own printer that is not so pretty and
dumps a textual representation that is very easily parsed so that the
AST can be reconstructed and insert that into my local version of
ocamlc?
I'm sure people have encountered similar problems before. Any advice
based on your experience would be very much appreciated.
-mulhern
next reply other threads:[~2005-02-24 3:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-24 3:25 mulhern [this message]
2005-02-24 7:02 ` [Caml-list] " Sylvain LE GALL
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e81dbc44e27d0078e72d08361979e0fd@cs.wisc.edu \
--to=mulhern@cs.wisc.edu \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox