《CPython Internals》阅读笔记:p97-p117

《CPython Internals》学习第 7 天,p97-p117 总结,总计 21 页。

一、技术总结

1.词法分析(lexical analysis)

根据《Compilers-Principles, Techniques, and Tools》(《编译原理》第2版)第 5 页:The first phase of a compiler is called lexical analysis or scanning. The lexcical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequences called lexemes. For each lexeme, the lexical analyzer produces as output a token of the form <token-name, attribute-value> that is passes on to the subsequent phase, syntax analysis。

执行词法分析(lexical analysis)的 component 称为 lexical analyzer(有时候也称为lexer, scanner, tokenizer)。

2.关于parser-tokenizer的一疑问

p92, Creating a concrete syntax tree using a parser-tokenizer, or lexer.

p92,The CST is created from a tokenizer and a parser.

说实话,我不是很理解作者为什么要将编译流程画成这样,以及为什么要用 parser-tokenizer这个术语,这样真是太混乱了。

流程图以及第一句表明 lexer 的输出是 CST, 但是第二句 CST的输出来自于 tokenizer 和 parser,简直就是前后矛盾。lexer 的输出是 token, 所以才有 tokenizer 这个称呼。 CST 是 parser 的输出。

以及最后又流入到 compiler,也是很莫名其妙, lexer 和 parser 其实属于 compiler。

3.AST

p102, The structure is a representation of the CST called an abstract syntax tree (AST).

p111,Abstract syntax tree (AST): A contextual tree representation of Python's grammar and statements.

看完上面这两个定义哪个读者能不迷糊。

二、英语总结(生词:0)

无。

关于英语的注解同步更新汇总到 https://github.com/codists/English-In-CS-Books 仓库。

三、其它

Lexing and Parsing With Syntax Trees: 本章作者介绍比较混乱,如果读者不熟悉编译原理的知识,那么最好先补充下编译原理知识,这样才能更好的理解本章内容。

四、参考资料

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)

相关推荐
山沐与山6 分钟前
【设计模式】Python责任链模式:从入门到实战
python·设计模式·责任链模式
luoluoal9 分钟前
基于python的图像的信息隐藏技术研究(源码+文档)
python·mysql·django·毕业设计·源码
电商API_1800790524719 分钟前
淘宝商品视频提取API全解析:从授权到落地实战
爬虫·python·信息可视化·数据分析·音视频
计算机程序设计小李同学27 分钟前
基于 Flask 的养猪场信息模拟系统
后端·python·flask
Iridescent112137 分钟前
Iridescent:Day38
python
熬夜敲代码的小N37 分钟前
2026 职场生存白皮书:Gemini Pro 实战使用指南
人工智能·python·ai·职场和发展
Franklin1 小时前
移植一个Pycharm的复杂项目:
ide·python·pycharm
94621931zyn61 小时前
外观设置 - Cordova 与 OpenHarmony 混合开发实战
笔记·python
彼岸花开了吗1 小时前
构建AI智能体:六十五、模型智能训练控制:早停机制在深度学习中的应用解析
人工智能·python
BoBoZz191 小时前
3D 医学扫描同时显示患者的皮肤、骨骼的 3D 模型(通过等值面提取),以及三个正交切片
python·vtk·图形渲染·图形处理