Code Monkey home page Code Monkey logo

craftinginterpreters_zh's Introduction

craftinginterpreters_zh

[ 在线阅读 ]

手撸解释器教程《Crafting Interpreters》中文翻译。

这是一个已基本完成的翻译项目,原项目是craftinginterpreters,同时还有配套的英文书,可免费在线阅读

该书由一门小型的自创语言Lox开始,分别使用Java和C实现了两种类型的解释器,jlox和clox,其中前者是将语法解析成Java中的表示代码,主要依赖Java本身的语法能力实现代码的真正运行;后者则采用了类似编译和虚拟机的机制,实现了一个看上去“更高效”的解释器。

该书中并不是只灌输概念或者只贴出代码,相反,作者经过悉心拆解解释器相关的概念,在每一章节中逐步进行讲解和实现,并且保证每个章节结束之后都有一个可以运行的解释器版本。内容上不会有太过深入的理论,对于普通编程爱好者也可以很容易地上手学习。

如果您的英语阅读能力比较强,建议直接阅读原文,同时也欢迎您参与本项目,分享自己学习的成果,帮助更多的人。

囿于本人能力限制,在译文难免有错漏或者含混之处,请积极留言,我会悉心听取大家的意见,争取可以让这篇译文帮助到更多人。

如果您觉得这篇译文对您的学习有所帮助,可以奖励作者一杯奶茶:)

支付宝 微信支付

进度

章节序号 章节名 内容简介 完成情况
I WELCOME 导读 已完成
1 Introduction 前言 已完成
2 A Map of the Territory 解释器简介 已完成
3 The Lox Language Lox语言介绍 已完成
II A TREE-WALK INTERPRETER jlox介绍 已完成
4 Scanning 扫描器相关 已完成
5 Representing Code 表示代码 已完成
6 Parsing Expressions 解析表达式 已完成
7 Evaluating Expressions 执行表达式 已完成
8 Statements and State 语句和状态 已完成
9 Control Flow 控制流 已完成
10 Functions 函数 已完成
11 Resolving and Binding 解析和绑定 已完成
12 Classes 已完成
13 Inheritance 继承 已完成
III A BYTECODE VIRTUAL MACHINE clox介绍 已完成
14 Chunks of Bytecode 字节码 已完成
15 A Virtual Machine 虚拟机 已完成
16 Scanning on Demand 扫描 已完成
17 Compiling Expressions 编译表达式 已完成
18 Types of Values 值类型 已完成
19 Strings 字符串 已完成
20 Hash Tables 哈希表 已完成
21 Global Variables 全局变量 已完成
22 Local Variables 局部变量 已完成
23 Jumping Back and Forth 来回跳转 已完成
24 Calls and Functions 调用和函数 已完成
25 Closures 闭包 已完成
26 Garbage Collection 垃圾回收 已完成
27 Classes and Instances 类和实例 已完成
28 Methods and Initializers 方法和初始化 已完成
29 Superclasses 超类 已完成
30 Optimization 优化 已完成
BACKMATTER 后记 已完成
A1 Appendix I: Lox Grammar Lox语法 已完成
A2 Appendix II: Generated Syntax Tree Classes 语法树类 已完成

PS:

文本中使用了很多Typora功能语法,建议使用Typora阅读,

特别鸣谢

感谢xieyuheng提供的在线阅读支持,为需要在线阅读markdown文档的同学推荐read-only项目,样式简约大方,值得一试。

craftinginterpreters_zh's People

Contributors

bit0r avatar boatrainlsz avatar chanyon avatar clausewitzcpu0 avatar cryo-cells avatar cyc4188 avatar dancon avatar guoyaxiang avatar haiboolang avatar isensen avatar itlantu avatar k997 avatar ltstrange avatar misaka-9982-coder avatar ndnovadev avatar rovast avatar shaochenheng avatar sweet2honey avatar ttkltll avatar uncle-lv avatar xieyuheng avatar zzzsyyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

craftinginterpreters_zh's Issues

2.1.2节 It turns out human languages are too messy for the rigid grammars those parsers could handle, but they were a perfect fit for the simpler artificial grammars of programming languages.

原翻译为:事实证明,相对那些解析器能够处理的严格语法来说,人类语言太混乱了;但对于编程语言中更简单的人工语法来说,人类语言却是完美的。
个人感觉应该翻译为:事实证明,对于那些语法严格的解析器来说,人类语言太混乱了,但是对于处理那些语法简单的编程语言来说,他们是再合适不过的了。

第17章编译表达式,"并将其存储中previous字段中"修改->"并将其存储在previous字段中"

Just like in jlox, it steps forward through the token stream. It asks the scanner for the next token and stores it for later use. Before doing that, t takes the old current token and stashes that in a previous field.That will come in handy later so that we can get at the lexeme after we match a token.

就像在jlox中一样,该函数向前通过标识流。它会向扫描器请求下一个词法标识,并将其存储起来以供后面使用。在此之前,它会获取旧的current标识,并将其存储中previous字段中。这在以后会派上用场,让我们可以在匹配到标识之后获得词素。

  • 加粗部分修改并将其存储在previous字段中

5.2 小标题漏译了

这个语法实际上是有歧义的,我们在解析它时就会看到这一点。但现在这已经足够了。

## 5 . 2 Implementing Syntax Trees

> Finally, we get to write some code. That little expression grammar is our skeleton. Since the grammar is recursive—note how `grouping`, `unary`, and `binary` all refer back to `expression`—our data structure will form a tree. Since this structure represents the syntax of our language, it’s called a **syntax tree**.

最后,我们要写一些代码。这个小小的表达式语法就是我们的骨架。由于语法是递归的——请注意`grouping`, `unary`, 和 `binary` 都是指回`expression`的——我们的数据结构将形成一棵树。因为这个结构代表了我们语言的语法,所以叫做**语法树**[^9]

5.2的小标题漏掉了

在线展示

你好,请问有意愿做一个类似于gitbook的在线网站显示这些翻译内容吗,感觉这样会比较方便阅读些。

2.领土地图 A Map of the Territory 中的翻译纠错

“Though the area explored by language designers is vast, the trails they’ve carved through it are few. Not every language takes the exact same path—some take a shortcut or two—but otherwise they are reassuringly similar from Rear Admiral Grace Hopper’s first COBOL compiler all the way to some hot new transpile-to-JavaScript language whose “documentation” consists entirely of a single poorly-edited README in a Git repository somewhere.”
尽管语言设计师所探索的领域辽阔,但他们所走过的路却很少。 并非每种语言都采用完全相同的路径(有些采用一种或两种捷径),但除此之外,从海军少将Grace Hopper的第一个COBOL编译器,一直到一些热门的新移植到JavaScript的语言,它们的 "文档 "完全是由Git仓库中一个编辑得很差的README组成的

原文中这段话主要是体现从古至今编程语言的变化相对较小,无论是古老的语言还是新兴语言,都采用了非常类似的结构。我建议这段修改为:
尽管语言设计师探索的领域辽阔,但是往往都走到相似的几条路上。虽然说并非所有语言都采用了相同的模式(有一些语言会采取一些捷径),但是无论是海军少将Grace Hopper的第一个COBOL语言还是近年来热门的JavaScript的语言(js的文档甚至完全是由git仓库中的一个编辑的很差的README组成的),都呈现出相似的特征,这十分令人欣慰。

11章节内parse和resolve都被译成了解析,有歧义

eg:

After the parser produces the syntax tree, but before the interpreter starts executing it, we’ll do a single walk over the tree to resolve all of the variables it contains.
解析器生成语法树之后,解释器执行语法树之前,我们会对语法树再进行一次遍历,以解析其中包含的变量。

parse一般指代对语法做解析,指通过token构建语法树的过程。而resolve指代的是类似“分析使用某物”的含义。

这里期待能用其他词汇替换一下,或者对于有歧义的位置对原有英文词汇予以保留。

(这种也算是中文的编译解释器相关内容的一个常见谬误了

文章很棒

中英对照的形式很好,有些中文没翻译到位的,可以直接查看英文,我本来也想翻译这篇文章,但是一直没有时间。如果需要人手,我可以帮忙翻译一些章节

希望可以帮忙一起翻译

我最近刚发现这本书,看了前边一部分觉得很不错,目前在github上看到您好像是唯一还在坚持翻译的人,我对编译器和语言也比较感兴趣,也曾参与过英文书籍的翻译,请问是否需要帮忙?

第15章、16章中图片无法显示

首先非常感谢作者的辛勤付出。让我等英语渣渣能比较便利的阅读这本书。
最近看到 15 章时发现图片无法显示。我看了下 markdown 中,使用了绝对路径。比如:
(D:\翻译学习\CraftingInterpreters\15.虚拟机\ast-16511998979731.png)
16章也是如此。
麻烦老兄修改一下。🙏
一键 replace 就好了。😄
如果需要的话我也可以提一个 pr.

8轨音乐

3.9.1 第一段里面, 8轨音乐这玩意是说的磁带...

在**大陆,通常“磁带”或者“录音带”一词都指紧凑音频盒带,因为它的应用非常广泛。在****reel-to-reel tape被称为盘式录音带、紧凑音频盒带(Compact audio cassette)被称为卡式录音带、8轨软片(8-track cartridges))被称为匣式录音带。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.