首选语言:C/ c++、Java、Ruby。
我正在寻找一些关于如何编写自己的编译器的有用书籍/教程,只是为了教育目的。我最熟悉C/ c++、Java和Ruby,所以我更喜欢包含这三者之一的资源,但任何好的资源都是可以接受的。
首选语言:C/ c++、Java、Ruby。
我正在寻找一些关于如何编写自己的编译器的有用书籍/教程,只是为了教育目的。我最熟悉C/ c++、Java和Ruby,所以我更喜欢包含这三者之一的资源,但任何好的资源都是可以接受的。
当前回答
最快的方法是读两本书:
JP Bennett的1990版《编译技术介绍,使用ANSI C, LeX和YaCC的第一课程》-示例代码,解析理论和设计的完美平衡-它包含了一个用C, LeX和YaCC编写的简单语法的完整编译器
龙书(旧版本)-主要是一个详细的参考功能没有涵盖在前一本书
其他回答
如果您不仅仅是在寻找书籍,而且还对有关于该主题的文章的网站感兴趣,我已经在博客中讨论了创建编程语言的各个方面。大部分文章都可以在我博客的“语言设计”类别中找到。
特别是,我介绍了手动生成Intel机器代码、自动生成机器码或字节码、创建字节码解释器、编写面向对象的运行时、创建简单的加载器以及编写简单的标记/清除垃圾收集器。所有这些都是非常实用和务实的方式,而不是用大量的理论让你感到无聊。
将感激反馈这些。
资源清单:
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文件 $印刷书籍的链接
I think Modern Compiler Implementation in ML is the best introductory compiler writing text. There's a Java version and a C version too, either of which might be more accessible given your languages background. The book packs a lot of useful basic material (scanning and parsing, semantic analysis, activation records, instruction selection, RISC and x86 native code generation) and various "advanced" topics (compiling OO and functional languages, polymorphism, garbage collection, optimization and single static assignment form) into relatively little space (~500 pages).
我更喜欢《现代编译器实现》而不是《Dragon》,因为《现代编译器实现》对该领域的调查较少——相反,它确实涵盖了编写一个严肃、体面的编译器所需的所有主题。在你读完这本书之后,如果你需要的话,你就可以直接深入研究论文了。
I must confess I have a serious soft spot for Niklaus Wirth's Compiler Construction. It is available online as a PDF. I find Wirth's programming aesthetic simply beautiful, however some people find his style too minimal (for example Wirth favors recursive descent parsers, but most CS courses focus on parser generator tools; Wirth's language designs are fairly conservative.) Compiler Construction is a very succinct distillation of Wirth's basic ideas, so whether you like his style or not or not, I highly recommend reading this book.
列表中缺少:Jones和Lins的《垃圾收集:自动动态内存管理的算法》。
(假设您正在编写编译器和运行时系统,并且正在实现一种垃圾收集语言。
Python附带了一个用Python编写的Python编译器。您可以看到源代码,它包括从解析、抽象语法树、发出代码等所有阶段。 破解它。