Compiler construction ocaml编译器是使用编译器前端模块解析来解析源代码还是使用ocamlyacc来解析源代码?

Compiler construction ocaml编译器是使用编译器前端模块解析来解析源代码还是使用ocamlyacc来解析源代码?,compiler-construction,ocaml,Compiler Construction,Ocaml,我试着阅读ocaml编译器的源代码,使用4.07源代码 我从driver/main.ml读取它 我注意到它使用driver/pparse.ml第161行函数“parse”来解析lex buf (我添加了一行Printf.Printf“pparse.parse”,在make world之后,我使用boot/ocamlrun./ocamlc-nostdlib-I stdlib-ca.ml对其进行测试,控制台写入“pparse.parse”): 我想知道Parse.implementation是函数实

我试着阅读ocaml编译器的源代码,使用4.07源代码

我从driver/main.ml读取它

我注意到它使用driver/pparse.ml第161行函数“parse”来解析lex buf (我添加了一行Printf.Printf“pparse.parse”,在make world之后,我使用boot/ocamlrun./ocamlc-nostdlib-I stdlib-ca.ml对其进行测试,控制台写入“pparse.parse”):

我想知道Parse.implementation是函数实现,它来自编译器前端库,如下所示:

来自parseing/parse.ml,第61行:

let implementation = wrap Parser.implementation
在“makeworld”之后,ocamlyacc在floder parse中生成parser.ml 在“make world”之后,函数Parser.implementation是:

let implementation (lexfun:Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) = 
(Parsing.yyparse yytables 1 lexfun lexbuf : Parsetree.structure)
我不知道ocaml编译器真正使用的是哪个

我更改函数parse如下所示:

let parse (type a) (kind : a ast_kind) lexbuf : a =
match kind with
| Structure -> 
Printf.printf "pparse.parse";
let a=Parse.implementation lexbuf in
let writehandle = open_out "/home/wk/prog/LocationTest/parsed" in
let fmt = Format.formatter_of_out_channel writehandle in
Format.fprintf fmt "%a@." Pprintast.structure a ;
close_out writehandle;
在“make world”之后,它工作正常。但是在boot/ocamlrun./ocamlc-nostdlib-I stdlib-c a.ml之后,解析的文件与a.ml相同,甚至a.ml也是一个复杂的程序

太复杂了吗?你能帮我吗?谢谢


有没有一本书或其他文档可以教我ocaml的编译器?谢谢

解析器本身由ocamlyacc(或ocaml4.08中的menhir)作为
parsing/parser.ml
parsing/parser.mly
生成。模块
parsing/parse
包装结果函数以添加一些解析器错误处理。最后,模块
driver/pparse
parsing/parse
之上的另一层,负责设置解析器环境和预处理阶段

然后,编译器libs库重新导出编译器的一些内部模块


请参阅以获取一些补充信息。

谢谢,因此“|Structure->Parse.implementation lexbuf”行中的“Parse.implementation”不是来自?但如何知道它?正如我所说,编译器libs捆绑了编译器的一些内部模块。因此,它与
解析/parse
完全相同,但编译器本身不使用编译器libs。
let parse (type a) (kind : a ast_kind) lexbuf : a =
match kind with
| Structure -> 
Printf.printf "pparse.parse";
let a=Parse.implementation lexbuf in
let writehandle = open_out "/home/wk/prog/LocationTest/parsed" in
let fmt = Format.formatter_of_out_channel writehandle in
Format.fprintf fmt "%a@." Pprintast.structure a ;
close_out writehandle;