开发者

Parsing C to Ocaml

I would like to get the Abstract Syntax Tree (AST) from a C code, into an OCaml value, so that I can further process the parsed code with a plain OCaml program.

I had in mind to use GCC, get the AST (in GIMPLE) with a hook, and convert the GIMPLE code to Ocaml.

But I wonder if there is another way, or if someone did something similar already. (I haven't found much actually on that...)

I don't want to resort to using CIL. It is an OCaml parser for C code, but it doesn't contain all 开发者_如何学编程optimizations that GCC has. (I especially need a deeper alias analysis than the one implemented in CIL).

Can LLVM be a good idea to look at? Already done maybe?

Any better idea?


If your problem with CIL is the precision of the provided alias analysis, take a look at Frama-C. It is based on CIL but provides a precise value analysis that works for pointers. The value analysis makes its results available inside a modular architecture.


An other option to parse C to Ocaml would be FrontC. Its description says :

FrontC is an OCAML library providing a C parser and lexer. The result is a syntactic tree easy to process with usual OCAML tree management.

It provides support for ANSI C syntax, old-C K&R style syntax and the standard GNU CC attributes.

It provides also a C pretty printer as an example of use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜