← 返回专栏列表

Crafting Interpreters:手写解释器

共 35 篇文章

11. Control Flow:条件分支、逻辑短路与循环

本章为 Lox 加入 conditional execution、logical operators、while 和 for loops,让程序能够根据状态改变执行路径。

12. Functions:调用、返回与 closure

本章为 Lox 加入 function call、function declaration、return 和 closure 的基础,让代码可以封装、复用并递归调用。

13. Resolving and Binding:静态作用域与变量解析

本章在 interpreter 运行前增加 resolver pass,计算每个变量引用对应的 lexical scope 距离,并修复 closure 中的绑定语义。

14. Classes:对象、方法与 this 绑定

本章为 Lox 加入 classes、instances、fields、methods、this,以及构造器和 initializer。

15. Inheritance:superclass、subclass 与 super call

本章为 Lox 加入 superclass、subclass 和 super call,完成 tree-walk interpreter 的面向对象特性。

16. A Bytecode Virtual Machine:从 jlox 到 clox

Part III 转向 C 实现的 bytecode virtual machine:在保留 Lox 语言语义的同时,深入执行、内存管理与 runtime 的底层机制。

17. Chunks of Bytecode:指令、常量与反汇编

本章为 clox 设计 bytecode chunk:用紧凑的 instruction、constant table 和 line information 表示可执行程序。

18. A Virtual Machine:stack、指令执行与算术

本章实现 clox 的核心 VM:通过 instruction pointer 读取 bytecode,并用 value stack 执行算术表达式。

19. Scanning on Demand:clox 的按需词法扫描

本章把 clox 的 scanner 接入 compilation pipeline,并逐个 token 扫描 source,让 compiler 可以按需取得词法单元。

20. Compiling Expressions:Pratt parser 与 bytecode 生成

本章实现 clox compiler 的 expression compilation:扫描 token、使用 Pratt parser 处理 precedence,并发出 bytecode。

第 2 / 4 页 · 共 35 篇