0

我目前有一个包含以下文件的项目(转到 Python 编译器)

ast.ml
parser.mly
lex.mll
weeder.ml
prettyPrint.ml
main.ml

以下是依赖项:

parser: ast
lexer: parser, Core, Lexing
weeder: ast
prettyPrint: ast
main: ast, lex, parser, weeder, prettyPrint

我尝试根据我阅读的文档进行以下编译:

$ menhir parser.mly
> Warning: you are using the standard library and/or the %inline keyword. We
  recommend switching on --infer in order to avoid obscure type error messages.

$ ocamllex lex.mll
> 209 states, 11422 transitions, table size 46942 bytes

$ ocamlbuild -no-hygiene main.native
> File "parser.mli", line 77, characters 56-59:
  Error: Unbound type constructor ast
  Command exited with code 2.
  Compilation unsuccessful after building 6 targets (2 cached) in 00:00:00.

ast.ml 包含一个类型声明列表,其中我有一个

type ast = ...

我现在花了几个小时阅读 ocamlfind、corebuild 和 ocamlopt 的文档,什么也没有。在某些时候,它似乎只是一个巧合而编译,并且再也没有工作过。我愿意使用任何工具。

这是 parser.mly 中的内容

%{
  open Ast

  exception ParserError of string

  let rec deOptionTypeInList tupleList =
    match tupleList with
      | [] -> []
      | (a, Some t)::tl -> (a, t)::(deOptionTypeInList tl)
      | _ -> raise (ParserError "no type given in type declaration")
%}

[ ... long list of tokens ... ]

%type <ast> prog (* that seems to be the problem *)
%type <string> packDec
%type <dec> dec
%type <dec> subDec
[...]

%start prog

[ ... rules ... ] 

这是错误消息中提到的最后一行。

val prog: (Lexing.lexbuf -> token) -> Lexing.lexbuf -> (ast)
4

1 回答 1

4

open Ast构造不会导出到.mli提及符号类型的文件中。尝试使用

%type <Ast.ast>

编辑:另外,你的构建命令很奇怪。您不应该手动调用ocamllexand menhir,因此不需要-no-hygiene. 删除所有生成的文件,然后做

ocamlbuild -use-menhir main.byte
于 2016-03-24T06:15:18.053 回答