現在、次のファイルを含むプロジェクト (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)