无法使用沙丘编译MLY文件
我正在写下我的第一个Ocamllex和ocamlyacc程序,通过以下 this tutorial
my dune我的dune files看起来像
(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 { () }
;
主
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"
。
File "bin/parser.mly", line 3: syntax error
%start <unit> prog
我的 它显示了如何解析和空字符串。我对这个错误不太了解,因为它没有告诉我语法错误是什么。我已经完全编写了代码,如视频所示。
I am writing my first Ocamllex and Ocamlyacc program by following this tutorial
My dune file looks like
(executable
(public_name Calculator)
(name main))
(ocamllex lexer)
(ocamlyacc parser)
My lexer.mll file is
{
open Parser
}
rule read = parse
| eof { EOF }
And parser.mly file is
%token EOF
%start <unit> prog
%%
prog:
| EOF { () }
;
My main.ml file is
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"
When I say dune build
I just get an error
File "bin/parser.mly", line 3: syntax error
%start <unit> prog
However the tutorial I am following (linked above) the same code compiles and runs. and it shows how to parse and empty string. I don't know much about this error because its not tell me what the syntax error is. I have written the code exactly as shown in the video.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为OcamlyAcc没有该
%start&lt; type&gt;符号
语法。您应该使用%type
单独指定类型:I think ocamlyacc doesn’t have that
%start <type> symbol
syntax. You should separately specify the type using%type
: