2
我正在編寫一個編譯器,它接受我的AST並輸出OCaml AST。當編譯:手工創建的OCaml中的未綁定值AST
(List.length '(1 2 3))
到
List.length [1; 2; 3]
我得到以下輸出AST:
[
structure_item (_none_[1,0+-1]..[1,0+-1]) ghost
Pstr_eval
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_apply
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_ident "List.length" (_none_[1,0+-1]..[1,0+-1]) ghost
[
<label> ""
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_construct "::" (_none_[1,0+-1]..[1,0+-1]) ghost
Some
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_tuple
[
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_constant Const_int 1
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_construct "::" (_none_[1,0+-1]..[1,0+-1]) ghost
Some
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_tuple
[
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_constant Const_int 2
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_construct "::" (_none_[1,0+-1]..[1,0+-1]) ghost
Some
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_tuple
[
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_constant Const_int 3
expression (_none_[1,0+-1]..[1,0+-1]) ghost
Pexp_construct "[]" (_none_[1,0+-1]..[1,0+-1]) ghost
None
]
]
]
]
]
經檢查,這似乎是幾乎相同的ocamlc -dparsetree
上述OCaml的程序的輸出,編譯成功。
相反,我的程序不與下面的錯誤編譯:
Error: Unbound value List.length
我在做什麼錯?
你是完全正確的。我會看一看。 – tekknolagi
關於輸出位置 - 不幸的是,我不支持AST。還沒。 – tekknolagi
我會建議快速做到這一點。除此之外,調試類型錯誤將成爲一場噩夢。 :p – Drup