在解析器,解释器和编译器上学习资源

时间:2021-06-08 20:46:28

I've been wanting to play around with writing my own language for a while now (ostensibly for the learning experience) and as such need to be relatively grounded in the construction of Parsers, Interpreters, and Compilers. So:

我一直想用自己的语言编写一段时间(表面上是为了学习经验),因此需要在构建解析器,解释器和编译器时相对基础。所以:

  • Does anyone know of any good resources on constructing Parsers, Interpreters, and Compilers?
  • 有谁知道构建解析器,解释器和编译器的任何好资源?

EDIT: I'm not looking for compiler-compilers/parser-compilers such as Lex, Yacc and Bison...

编辑:我不是在寻找编译器编译器/解析器编译器,如Lex,Yacc和Bison ......

12 个解决方案

#1


12  

The best paper I ever read on compilers is dated 1964 "META II a syntax-oriented compiler writing language" by Val Schorre. (http://doi.acm.org/10.1145/800257.808896)

我在编译器上读过的最好的论文是1964年由Val Schorre撰写的“META II语法编译器编写语言”。 (http://doi.acm.org/10.1145/800257.808896)

In 10 pages, he shows you how to build an astoundingly simple but very effective compiler-compiler, provides you with with the compiler-compiler grammar and provides you with enough details for you to hand implement it in an afternoon (with one astonishing conceptual moment when you realize how it recurses), and just for grins implements an ALGOL-like language. The paper is a complete gas and really should be required reading for anybody working with compiler technology.

在10页中,他向您展示了如何构建一个令人惊讶的简单但非常有效的编译器编译器,为您提供编译器编译器语法,并为您提供足够的详细信息,以便您在下午手动实现它(具有一个惊人的概念时刻)当你意识到它如何递归时),只是因为grins实现了类似ALGOL的语言。这篇论文是一个完整的气体,对于任何使用编译器技术的人来说,确实应该阅读。

Here's a link to play with an great tutorial on metacompiling, based on the paper. http://www.bayfronttechnologies.com/mc_tutorial.html

根据论文,这里有一个关于元编译的精彩教程的链接。 http://www.bayfronttechnologies.com/mc_tutorial.html

#2


8  

Aho's "Dragon book" is the standard reference, but another good choice is Andrew Appel's Modern Compiler Implementation in Java (also available in ML and C flavors). It walks you step-by-step through each of the necessary components of a compiler/interpreter and provides a lot of useful source code.

Aho的“Dragon book”是标准参考,但另一个不错的选择是Andrew Appel的Java编译实现(也有ML和C版本)。它逐步引导您逐步完成编译器/解释器的每个必要组件,并提供许多有用的源代码。

#3


8  

This highly-entertaining blog post by Steve Yegge (Rich Programmer Food) won't tell you everything you need to know about how to build a compiler (although it does include a fair amount of good insight), but it does a great job of explaining why you want to understand compliers.

Steve Yegge(Rich Programmer Food)的这篇极具娱乐性的博客文章不会告诉你关于如何构建编译器需要了解的所有信息(尽管它确实包含了相当多的良好洞察力),但是它做得很好解释你为什么要理解编码器。

Heck, that post almost got me to start studying compilers, and I have a full-time job, a 3-year-old at home, and about -1.5 free hours per day on average.

哎呀,这篇文章几乎让我开始学习编译器,我有一份全职工作,一个3岁的家庭,平均每天约1.5小时。

#4


6  

Not very easy, but exhaustive: the dragon book

不是很容易,但详尽无遗:龙书

#5


4  

Compiler Construction: Principles and Practice is a best book on the subject.

编译器构造:原理和实践是关于该主题的最佳书籍。

#6


4  

The MIT OpenCourseWare(OCW) site has a class whose project is to build a complier...they refer to the Dragon book and Appel's book, but in addition, there are also class notes and lectures available. The class is 6.035 - Computer Language Engineering.

麻省理工学院开放式课件(OCW)网站有一个课程,其项目是建立一个编辑器...他们参考龙书和Appel的书,但此外,还有课堂笔记和讲座。该课程是6.035 - 计算机语言工程。

I found the class notes very useful for explaining recursive-descent parsers.

我发现类注释对于解释递归下降解析器非常有用。

#7


4  

I've found "Let's build a compiler" - the tutorial by Jack Crenshaw, very easy to follow and understand. Jack builds a compiler for Pascal, from the ground up, with very detailed explanations of every step.

我发现“让我们构建一个编译器” - Jack Crenshaw的教程,很容易理解和理解。 Jack从头开始为Pascal构建编译器,并对每个步骤进行非常详细的解释。

#8


3  

I recently read Programming Language Processors in Java and would recommend it to you as it starts with basic concepts and then takes you through the implementation of a recursive-descent compiler including code generation with plenty of discussion of alternative approaches. I've not read the other suggested books in this thread though, so can't offer a comparison with those. Don't be put off by the In Java part, if you don't know java, as the concepts and their implementation are well enough explained that you get the gist without needing a detailed understanding of Java.

我最近阅读了Java中的编程语言处理器,并将向您推荐它,因为它从基本概念开始,然后引导您完成递归下降编译器的实现,包括代码生成以及对替代方法的大量讨论。我没有读过这个帖子中的其他推荐书籍,所以无法与这些书籍进行比较。如果您不了解Java,请不要被In Java部分推迟,因为概念和它们的实现已经很好地解释了您在不需要详细了解Java的情况下获得要点。

#9


2  

I recommend Compiler Design in C which you would have to find in a used book site unfortunately. The only real problem with the book is that it was written back when speed of compilation was an important factor so the compiler is written in C. That's enough of a low level language that sometimes the implementation theory is buried under the implementation code.

我推荐C语言中的编译器设计,不幸的是你必须在二手书网站上找到它。这本书唯一真正的问题是,当编译速度是一个重要因素时,它被写回来,因此编译器是用C语言编写的。这足以成为一种低级语言,有时实现理论隐藏在实现代码之下。

You mentioned both Interpreters and Compilers. I'd actually recommend starting with an Interpreter rather than a Compiler. It's much easier to get started with an Interpreter and they tend to be more fun to work on because you can get immediate feedback on how you're doing.

你提到了口译员和编译器。我实际上建议从解释器而不是编译器开始。开始使用口译员要容易得多,而且他们的工作往往更有趣,因为您可以立即获得有关您的工作方式的反馈。

#10


2  

Just in case you:

以防你:

  • Are willing to play
  • 愿意发挥

  • Like the chance to build something quicker, then go deeper
  • 就像有机会更快地建立一些东西,然后更深入

  • Are ok with using .NET at an underlying platform
  • 在底层平台上使用.NET是否可以

...then I'd recommend you to check Microsoft's Dynamic Language Runtime, which is provided as source code inside the whole Dynamic Silverlight SDK.

...然后我建议您查看Microsoft的动态语言运行时,它是整个Dynamic Silverlight SDK中的源代码。

http://www.codeplex.com/sdlsdk

Some nice things about it is that it provides lots of ready-to-use features like a console, a common type system, a generic abstract syntax tree, etc. And the package includes three implementations: Python, Ruby and Javascript.

它的一些好处是它提供了许多现成的功能,如控制台,通用类型系统,通用抽象语法树等。该软件包包括三个实现:Python,Ruby和Javascript。

Maybe it is a good chance to implement a short language other the DLR, then start checking the actual DLR code, and then start building the basic stuff on your own.

也许这是一个很好的机会在DLR之外实现一种简短的语言,然后开始检查实际的DLR代码,然后开始自己构建基本的东西。

In any case, best luck from another language freak!

无论如何,从另一种语言怪胎中获得好运!

#11


1  

RE: lex, yacc, bison

RE:lex,yacc,bison

Do you mean you don't need pointers to them or that you aren't interested in using them? I don't recommend writing a lexer or parser by hand.

你的意思是你不需要指向它们或者你不想使用它们吗?我不建议手工编写词法分析器或解析器。

EDIT: You may have an exaggerated sense of what a "compiler-compiler" can accomplish: the really hard part of compilation begins after you've built the AST. The Aho, Louden, and Appel books are all quite good.

编辑:你可能夸大了“编译器 - 编译器”可以完成的事情:编译后真正困难的部分就是在你构建AST之后开始的。 Aho,Louden和Appel的书都很好。

#12


0  

It's an old book, and rather dated, but I've found Brinch Hansen on Pascal Compilers to be a very practical introduction to creating a language and building the elements of a compiler. Despite the name, it's not specific to Pascal. It's very worthwhile if you can find a copy.

这是一本旧书,相当陈旧,但我发现在Pascal编译器上的Brinch Hansen是一个非常实用的介绍,用于创建语言和构建编译器的元素。尽管有这个名字,但它并不是特定于Pascal的。如果你能找到一份副本,这是非常值得的。

#1


12  

The best paper I ever read on compilers is dated 1964 "META II a syntax-oriented compiler writing language" by Val Schorre. (http://doi.acm.org/10.1145/800257.808896)

我在编译器上读过的最好的论文是1964年由Val Schorre撰写的“META II语法编译器编写语言”。 (http://doi.acm.org/10.1145/800257.808896)

In 10 pages, he shows you how to build an astoundingly simple but very effective compiler-compiler, provides you with with the compiler-compiler grammar and provides you with enough details for you to hand implement it in an afternoon (with one astonishing conceptual moment when you realize how it recurses), and just for grins implements an ALGOL-like language. The paper is a complete gas and really should be required reading for anybody working with compiler technology.

在10页中,他向您展示了如何构建一个令人惊讶的简单但非常有效的编译器编译器,为您提供编译器编译器语法,并为您提供足够的详细信息,以便您在下午手动实现它(具有一个惊人的概念时刻)当你意识到它如何递归时),只是因为grins实现了类似ALGOL的语言。这篇论文是一个完整的气体,对于任何使用编译器技术的人来说,确实应该阅读。

Here's a link to play with an great tutorial on metacompiling, based on the paper. http://www.bayfronttechnologies.com/mc_tutorial.html

根据论文,这里有一个关于元编译的精彩教程的链接。 http://www.bayfronttechnologies.com/mc_tutorial.html

#2


8  

Aho's "Dragon book" is the standard reference, but another good choice is Andrew Appel's Modern Compiler Implementation in Java (also available in ML and C flavors). It walks you step-by-step through each of the necessary components of a compiler/interpreter and provides a lot of useful source code.

Aho的“Dragon book”是标准参考,但另一个不错的选择是Andrew Appel的Java编译实现(也有ML和C版本)。它逐步引导您逐步完成编译器/解释器的每个必要组件,并提供许多有用的源代码。

#3


8  

This highly-entertaining blog post by Steve Yegge (Rich Programmer Food) won't tell you everything you need to know about how to build a compiler (although it does include a fair amount of good insight), but it does a great job of explaining why you want to understand compliers.

Steve Yegge(Rich Programmer Food)的这篇极具娱乐性的博客文章不会告诉你关于如何构建编译器需要了解的所有信息(尽管它确实包含了相当多的良好洞察力),但是它做得很好解释你为什么要理解编码器。

Heck, that post almost got me to start studying compilers, and I have a full-time job, a 3-year-old at home, and about -1.5 free hours per day on average.

哎呀,这篇文章几乎让我开始学习编译器,我有一份全职工作,一个3岁的家庭,平均每天约1.5小时。

#4


6  

Not very easy, but exhaustive: the dragon book

不是很容易,但详尽无遗:龙书

#5


4  

Compiler Construction: Principles and Practice is a best book on the subject.

编译器构造:原理和实践是关于该主题的最佳书籍。

#6


4  

The MIT OpenCourseWare(OCW) site has a class whose project is to build a complier...they refer to the Dragon book and Appel's book, but in addition, there are also class notes and lectures available. The class is 6.035 - Computer Language Engineering.

麻省理工学院开放式课件(OCW)网站有一个课程,其项目是建立一个编辑器...他们参考龙书和Appel的书,但此外,还有课堂笔记和讲座。该课程是6.035 - 计算机语言工程。

I found the class notes very useful for explaining recursive-descent parsers.

我发现类注释对于解释递归下降解析器非常有用。

#7


4  

I've found "Let's build a compiler" - the tutorial by Jack Crenshaw, very easy to follow and understand. Jack builds a compiler for Pascal, from the ground up, with very detailed explanations of every step.

我发现“让我们构建一个编译器” - Jack Crenshaw的教程,很容易理解和理解。 Jack从头开始为Pascal构建编译器,并对每个步骤进行非常详细的解释。

#8


3  

I recently read Programming Language Processors in Java and would recommend it to you as it starts with basic concepts and then takes you through the implementation of a recursive-descent compiler including code generation with plenty of discussion of alternative approaches. I've not read the other suggested books in this thread though, so can't offer a comparison with those. Don't be put off by the In Java part, if you don't know java, as the concepts and their implementation are well enough explained that you get the gist without needing a detailed understanding of Java.

我最近阅读了Java中的编程语言处理器,并将向您推荐它,因为它从基本概念开始,然后引导您完成递归下降编译器的实现,包括代码生成以及对替代方法的大量讨论。我没有读过这个帖子中的其他推荐书籍,所以无法与这些书籍进行比较。如果您不了解Java,请不要被In Java部分推迟,因为概念和它们的实现已经很好地解释了您在不需要详细了解Java的情况下获得要点。

#9


2  

I recommend Compiler Design in C which you would have to find in a used book site unfortunately. The only real problem with the book is that it was written back when speed of compilation was an important factor so the compiler is written in C. That's enough of a low level language that sometimes the implementation theory is buried under the implementation code.

我推荐C语言中的编译器设计,不幸的是你必须在二手书网站上找到它。这本书唯一真正的问题是,当编译速度是一个重要因素时,它被写回来,因此编译器是用C语言编写的。这足以成为一种低级语言,有时实现理论隐藏在实现代码之下。

You mentioned both Interpreters and Compilers. I'd actually recommend starting with an Interpreter rather than a Compiler. It's much easier to get started with an Interpreter and they tend to be more fun to work on because you can get immediate feedback on how you're doing.

你提到了口译员和编译器。我实际上建议从解释器而不是编译器开始。开始使用口译员要容易得多,而且他们的工作往往更有趣,因为您可以立即获得有关您的工作方式的反馈。

#10


2  

Just in case you:

以防你:

  • Are willing to play
  • 愿意发挥

  • Like the chance to build something quicker, then go deeper
  • 就像有机会更快地建立一些东西,然后更深入

  • Are ok with using .NET at an underlying platform
  • 在底层平台上使用.NET是否可以

...then I'd recommend you to check Microsoft's Dynamic Language Runtime, which is provided as source code inside the whole Dynamic Silverlight SDK.

...然后我建议您查看Microsoft的动态语言运行时,它是整个Dynamic Silverlight SDK中的源代码。

http://www.codeplex.com/sdlsdk

Some nice things about it is that it provides lots of ready-to-use features like a console, a common type system, a generic abstract syntax tree, etc. And the package includes three implementations: Python, Ruby and Javascript.

它的一些好处是它提供了许多现成的功能,如控制台,通用类型系统,通用抽象语法树等。该软件包包括三个实现:Python,Ruby和Javascript。

Maybe it is a good chance to implement a short language other the DLR, then start checking the actual DLR code, and then start building the basic stuff on your own.

也许这是一个很好的机会在DLR之外实现一种简短的语言,然后开始检查实际的DLR代码,然后开始自己构建基本的东西。

In any case, best luck from another language freak!

无论如何,从另一种语言怪胎中获得好运!

#11


1  

RE: lex, yacc, bison

RE:lex,yacc,bison

Do you mean you don't need pointers to them or that you aren't interested in using them? I don't recommend writing a lexer or parser by hand.

你的意思是你不需要指向它们或者你不想使用它们吗?我不建议手工编写词法分析器或解析器。

EDIT: You may have an exaggerated sense of what a "compiler-compiler" can accomplish: the really hard part of compilation begins after you've built the AST. The Aho, Louden, and Appel books are all quite good.

编辑:你可能夸大了“编译器 - 编译器”可以完成的事情:编译后真正困难的部分就是在你构建AST之后开始的。 Aho,Louden和Appel的书都很好。

#12


0  

It's an old book, and rather dated, but I've found Brinch Hansen on Pascal Compilers to be a very practical introduction to creating a language and building the elements of a compiler. Despite the name, it's not specific to Pascal. It's very worthwhile if you can find a copy.

这是一本旧书,相当陈旧,但我发现在Pascal编译器上的Brinch Hansen是一个非常实用的介绍,用于创建语言和构建编译器的元素。尽管有这个名字,但它并不是特定于Pascal的。如果你能找到一份副本,这是非常值得的。