《CPython Internals》学习第 4 天,p61-p75 总结,总计 15 页。
一、技术总结
1.编译器类型
(1)self-hosted compiler
Self-hosted compilers are compilers written in the language they compile, such as the Go compiler. This is done by a process known as bootstrapping.
wiki 上写的是 self-hosting compiler, 不知道作者为什么要改成 self-hosted。
(2)source-to-source compiler
Source-to-source compilers are compilers written in another language that already has a compiler.
2.compiler-compiler
(1)定义
tools used to generate compilers。也称为compiler generator。在一些不严谨的表述中,本来应该属于 parser generator的工具也称为 compiler generator——Well first the term compiler-compiler has been degraded to include parser generators. I blame that on yacc(yet another compiler-compiler) calling itself a compiler compiler.
(2)示例
META II, TREEMETA, CWIC。
3.parser generator
(1)定义
A parser generator is a tool that generates a parser from a formal description of a language's grammar.
(2)示例
Bison,YACC,ANTLR。
二、英语总结(生词:0)
1.automaton % automata
(1)automaton: auto-("self") + matos("thinking, willing")
c. an automaton originally referred to something that moves or operates by itself(自动机).
The CPython parser was rewritten in Python 3.9 from a parser table automaton (the pgen module) into a contextual grammar parser(注:《CPython Internals》第 69 页)。
因为这里是一种自动机,所以使用的是 automaton。
(2)automata
automata 是 automaton 的复数形式。有一本很有名的计算机教材名字叫做《Introduction to Automata Theory, Languages, and Computation》(自动机理论、语言和计算导论)。
当讨论 multiple machines, general theory 时使用automata, 虽然从中文角度来说意思都一样,都是指“自动机”。
关于英语的注解同步更新汇总到 https://github.com/codists/English-In-CS-Books 仓库。
三、其它
The Python Language and Grammar 章节简评:介绍了 Python 编译器为什么使用 C语言开发——简单来说就是历史原因,Python 语言规范,parser-generator。
相对而言介绍得比较简单,需要读者自行查阅资料的地方比较多——"There are also tools available that can take a language specification and create a parser, which you’ll learn about later in this chapter. Popular compiler-compilers include GNU Bison, Yacc, and ANTLR。作者在第一句用 parser, 然后第二句又用 compiler-compiler(compiler-generator),最后的章节标题用的又是 Parser Generator,主打的就是一个随意。这里其实说的是 parser,GNU Bison, Yacc, and ANTLR 都是 parser generator, 咱就不能统一一下,尽量统一名称或者补充说明一下不行吗?不同的名称切换来切换去的,容易把不熟的读者绕晕。
四、参考资料
1. 编程
(1) Anthony Shaw,《CPython Internals》:https://book.douban.com/subject/35405785/
2. 英语
(1) Etymology Dictionary:https://www.etymonline.com
(2) Cambridge Dictionary:https://dictionary.cambridge.org
欢迎搜索及关注:编程人(a_codists)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。