《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)

相关推荐
Dream of maid几秒前
Python基础4(函数)
开发语言·python
vx_biyesheji00013 分钟前
计算机毕业设计:Python城市交通出行模式挖掘系统 Django框架 可视化 数据分析 PyEcharts 交通 深度学习(建议收藏)✅
人工智能·python·深度学习·数据分析·django·汽车·课程设计
yuanmazhiwu6 分钟前
计算机毕业设计:Python智慧出行数据分析与模式识别系统 Django框架 可视化 数据分析 PyEcharts 交通 深度学习(建议收藏)✅
人工智能·python·算法·数据分析·django·flask·课程设计
bKYP953cL10 分钟前
Flask - 常见应用部署方案
后端·python·flask
Dream of maid17 分钟前
Python-基础1(数据类型)
开发语言·python
清水白石00818 分钟前
《从缓存到数据库:一致性之痛与工程之道》
数据库·python·缓存
Thomas.Sir20 分钟前
第三章:Agent智能体开发实战之【LlamaIndex 工作流从入门到实战】
python·ai·llama·workflow·llamaindex
小江的记录本26 分钟前
【JEECG Boot】JEECG Boot 系统性知识体系全方位结构化总结
java·前端·spring boot·后端·python·spring·spring cloud
SomeB1oody27 分钟前
【Python深度学习】1.2. 多层感知器MLP(人工神经网络)实现非线性分类理论
开发语言·人工智能·python·深度学习·机器学习·分类
清水白石00830 分钟前
《从同步到消息驱动:现代后端交互模式的深度解析与工程实践》
python·交互