2017-02-24 7 views
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 
           ] 
         ] 
       ] 
     ] 
] 

, 이것은 위의 OCaml의 프로그램에 대한 ocamlc -dparsetree의 출력과 거의 동일한 것을, 성공적으로 컴파일됩니다.

대신, 내 프로그램은 다음과 같은 오류와 함께 컴파일되지 않습니다 :

Error: Unbound value List.length 

을 내가 잘못 뭐하는 거지?

답변

4

야생 추측 : Lident "List.length"을 작성하고 있습니다. 잘못된 것입니다. Lident은 정규화되지 않은 식별자입니다. Longident.parse "List.length"을 사용해야합니다. Ldot (Lident "List", "length")

사이드 노트 : 실제로 더 좋은 위치를 출력해야합니다. ;)

+0

당신은 완전히 옳습니다. 내가 한번 볼게. – tekknolagi

+0

출력 위치 관련 - 불행히도 AST에서 지원하지 않습니다. 아직. – tekknolagi

+1

나는 그것을 빨리 할 것을 권고한다. 디버깅 유형 오류는 그렇지 않으면 악몽이 될 것입니다. : p – Drup