首选语言:C/ c++、Java、Ruby。
我正在寻找一些关于如何编写自己的编译器的有用书籍/教程,只是为了教育目的。我最熟悉C/ c++、Java和Ruby,所以我更喜欢包含这三者之一的资源,但任何好的资源都是可以接受的。
首选语言:C/ c++、Java、Ruby。
我正在寻找一些关于如何编写自己的编译器的有用书籍/教程,只是为了教育目的。我最熟悉C/ c++、Java和Ruby,所以我更喜欢包含这三者之一的资源,但任何好的资源都是可以接受的。
当前回答
我记得大约七年前问过这个问题,当时我对编程还是个新手。
我问的时候非常小心,令人惊讶的是,我没有像你们在这里受到那么多批评。然而,他们确实给我指出了“龙书”的方向,在我看来,这是一本真正伟大的书,解释了编写编译器所需知道的一切(当然,你必须掌握一两种语言)。你懂的语言越多越好。
是的,很多人说读那本书是疯狂的,你不会从中学到任何东西,但我完全不同意这种说法。
许多人还说编写编译器是愚蠢和毫无意义的。编译器开发之所以有用,原因有很多:
因为它很有趣。 它是有教育意义的,当你学习如何编写编译器时,你会学到很多计算机科学和其他技术,这些技术在编写其他应用程序时很有用。 如果没有人编写编译器,现有的语言就不会变得更好。
我没有立即编写自己的编译器,但在询问之后,我知道从哪里开始。现在,在学习了许多不同的语言和阅读了龙书之后,写作并不是什么大问题。(我也在学习计算机工程,但我对编程的大部分知识都是自学的。)
总之,《龙之书》是一个很棒的“教程”。但是在尝试编写编译器之前,先花些时间掌握一两种语言。不过,不要指望在未来十年左右成为编译器大师。
如果你想学习如何编写解析器/解释器,这本书也是不错的选择。
其他回答
As an starting point, it will be good to create a recursive descent parser (RDP) (let's say you want to create your own flavour of BASIC and build a BASIC interpreter) to understand how to write a compiler. I found the best information in Herbert Schild's C Power Users, chapter 7. This chapter refers to another book of H. Schildt "C The complete Reference" where he explains how to create a calculator (a simple expression parser). I found both books on eBay very cheap. You can check the code for the book if you go to www.osborne.com or check in www.HerbSchildt.com I found the same code but for C# in his latest book
资源清单:
A Nanopass Framework for Compiler Education ¶ Advanced Compiler Design and Implementation $ An Incremental Approach to Compiler Construction ¶ ANTLR 3.x Video Tutorial Basics of Compiler Design Building a Parrot Compiler Compiler Basics Compiler Construction $ Compiler Design and Construction $ Crafting a Compiler with C $ Crafting Interpreters [Compiler Design in C] 12 ¶ Compilers: Principles, Techniques, and Tools $ — aka "The Dragon Book"; widely considered "the book" for compiler writing. Engineering a Compiler $ Essentials of Programming Languages Flipcode Article Archive (look for "Implementing A Scripting Engine by Jan Niestadt") Game Scripting Mastery $ How to build a virtual machine from scratch in C# ¶ Implementing Functional Languages Implementing Programming Languages (with BNFC) Implementing Programming Languages using C# 4.0 Interpreter pattern (described in Design Patterns $) specifies a way to evaluate sentences in a language Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages $ Let's Build a Compiler by Jack Crenshaw — The PDF ¶ version (examples are in Pascal, but the information is generally applicable) Linkers and Loaders $ (Google Books) Lisp in Small Pieces (LiSP) $ LLVM Tutorial Modern Compiler Implementation in ML $ — There is a Java $ and C $ version as well - widely considered a very good book Object-Oriented Compiler Construction $ Parsing Techniques - A Practical Guide Project Oberon ¶ - Look at chapter 13 Programming a Personal Computer $ Programing Languages: Application and Interpretation Rabbit: A Compiler for Scheme¶ Reflections on Trusting Trust — A quick guide Roll Your Own Compiler for the .NET framework — A quick tutorial from MSDN Structure and Interpretation of Computer Programs Types and Programming Languages Want to Write a Compiler? - a quick guide Writing a Compiler in Ruby Bottom Up Compiling a Lisp — compile directly to x86-64
传说:
链接到PDF文件 $印刷书籍的链接
这是一个庞大的课题。不要低估这一点。不要低估我的观点。 我听说龙之书是一个(?)开始的地方,连同搜索。(收集学会寻找,最终它将成为你的人生。 构建自己的编程语言绝对是一个很好的练习!但你要知道,它最终永远不会被用于任何实际目的。这种情况很少有例外。
Python附带了一个用Python编写的Python编译器。您可以看到源代码,它包括从解析、抽象语法树、发出代码等所有阶段。 破解它。
我也喜欢Crenshaw的教程,因为它非常清楚地说明了编译器只是另一个程序,它读取一些输入并写出一些输出。
阅读它。
如果您愿意,可以使用它,但随后查看另一篇关于如何编写更大、更完整的编译器的参考文献。
阅读《关于信任的信任》,了解一下在这个领域可以做的不明显的事情。