《CPython Internals》閱讀筆記:p61-p75
《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)
浙公網安備 33010602011771號