parsing ディレクトリに主なソースがある misc 内のコードも参照している
Makefile
これを使って make bcl する。 parse.cma が作成されるのでこれをloadすれば よい。
Todo: リンク順を求める。graph.ml
prefixでまとめてグラフ折り畳みそして、単純な関数適用をparseしてみた。
Pexp_applyが関数適用であることを表しているようだ
# let l = Lexing.from_channel stdin;; val l : Lexing.lexbuf = ... # Parse.implementation l;; f x;; - : Parsetree.structure = [{Parsetree.pstr_desc = Parsetree.Pstr_eval {Parsetree.pexp_desc = Parsetree.Pexp_apply ({Parsetree.pexp_desc = Parsetree.Pexp_ident (Longident.Lident "f"); Parsetree.pexp_loc = {Location.loc_start = 0; Location.loc_end = 1; Location.loc_ghost = false}}, [("", {Parsetree.pexp_desc = Parsetree.Pexp_ident (Longident.Lident "x"); Parsetree.pexp_loc = {Location.loc_start = 2; Location.loc_end = 3; Location.loc_ghost = false}})]); Parsetree.pexp_loc = {Location.loc_start = 0; Location.loc_end = 3; Location.loc_ghost = false}}; Parsetree.pstr_loc = {Location.loc_start = 0; Location.loc_end = 3; Location.loc_ghost = true}}]
Parsetree.Pexp_apply(関数情報, [引数情報のリスト])
さて、訪問してみましょうかそのまえに、Printastという神様のようなモジュールを発見。使ってみる。
このPrintastを改造すればいろいろできそう!!
# let t = Parse.implementation l;; f x;; val t : Parsetree.structure = ... # Printast.implementation (Format.formatter_of_out_channel stdout) t;; structure_item (0,3) ghost Pstr_eval expression (0,3) Pexp_apply expression (0,1) Pexp_ident "f" <label> "" expression (2,3) Pexp_ident "x" - : unit = () #let f = g() ではうまくいった静的なコールグラフを書くプログラム。(let (x,y) = .. に対応していない。 クラスについてはでたらめ)
visit.ml