无法使用 Dune 编译 MLY 文件

Not able to compile MLY file using Dune

我正在按照 this 教程

编写我的第一个 Ocamllex 和 Ocamlyacc 程序

我的沙丘文件看起来像

(executable
 (public_name Calculator)
 (name main))
(ocamllex lexer)
(ocamlyacc parser)

我的lexer.mll文件是

{
  open Parser
}

rule read = parse
  | eof { EOF }

而parser.mly文件是

%token EOF

%start <unit> prog

%%

prog:
  | EOF { () }
  ;

我的main.ml文件是

type expr = unit 

(** [parse s] parses string [s] into an AST. *)
let parse (s: string): expr = 
  let lexbuf = Lexing.from_string s in 
  let ast = Parser.prog Lexer.read lexbuf in 
  ast

(** [interp s] interprets [s] by Lexing and parsing it, 
    evaluating it, and converting the result into string *)
let interp (s: string) : string = 
  failwith "unimplemented"

当我说 dune build 我只是得到一个错误

File "bin/parser.mly", line 3: syntax error
%start <unit> prog

但是我遵循的教程(以上链接)编译并运行了相同的代码。它展示了如何解析和清空字符串。我不太了解这个错误,因为它没有告诉我语法错误是什么。我已经完全按照视频中的代码编写了代码。

我认为 ocamlyacc 没有 %start <type> symbol 语法。您应该使用 %type:

单独指定类型
%type <unit> prog
%start prog