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