首选语言: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文件 $印刷书籍的链接

还有一本书还没有推荐,但非常重要,那就是约翰·莱文的《链接器和加载器》。如果您不使用外部汇编程序,则需要一种方法来输出可以链接到最终程序的目标文件。即使您正在使用外部汇编程序,也可能需要了解重定位以及整个程序加载过程如何工作,以制作一个工作工具。这本书收集了很多关于各种系统的这个过程的随机知识,包括Win32和Linux。

如果你没有时间,我推荐Niklaus Wirth的“编译器构造”(Addison-Wesley)。1996年),一本你一天就能读完的小册子,但它解释了基础知识(包括如何实现词法分析器、递归下降解析器和你自己的基于堆栈的虚拟机)。在那之后,如果你想深入了解,就像其他评论者建议的那样,没有办法绕过龙的书。

抱歉,这是西班牙文,但这是阿根廷一门名为“Compiladores e Intérpretes”(编译器和口译员)的课程的参考书目。

这门课程从形式化语言理论到编译器构造,这些是你至少构建一个简单的编译器所需要的主题:

Compilers Design in C. Allen I. Holub Prentice-Hall. 1990. Compiladores. Teoría y Construcción. Sanchís Llorca, F.J. , Galán Pascual, C. Editorial Paraninfo. 1988. Compiler Construction. Niklaus Wirth Addison-Wesley. 1996. Lenguajes, Gramáticas y Autómatas. Un enfoque práctico. Pedro Isasi Viñuela, Paloma Martínez Fernández, Daniel Borrajo Millán. Addison-Wesley Iberoamericana (España). 1997. The art of compiler design. Theory and practice. Thomas Pittman, James Peters. Prentice-Hall. 1992. Object-Oriented Compiler Construction. Jim Holmes. Prentice Hall, Englewood Cliffs, N.J. 1995 Compiladores. Conceptos Fundamentales. B. Teufel, S. Schmidt, T. Teufel. Addison-Wesley Iberoamericana. 1995. Introduction to Automata Theory, Languages, and Computation. John E. Hopcroft. Jeffref D. Ullman. Addison-Wesley. 1979. Introduction to formal languages. György E. Révész. Mc Graw Hill. 1983. Parsing Techniques. A Practical Guide. Dick Grune, Ceriel Jacobs. Impreso por los autores. 1995 http://www.cs.vu.nl/~dick/PTAPG.html Yacc: Yet Another Compiler-Compiler. Stephen C. Johnson Computing Science Technical Report Nº 32, 1975. Bell Laboratories. Murray Hill, New Jersey. Lex: A Lexical Analyzer Generator. M. E. Lesk, E. Schmidt. Computing Science Technical Report Nº 39, 1975. Bell Laboratories. Murray Hill, New Jersey. lex & yacc. John R. Levine, Tony Mason, Doug Brown. O’Reilly & Associates. 1995. Elements of the theory of computation. Harry R. Lewis, Christos H. Papadimitriou. Segunda Edición. Prentice Hall. 1998. Un Algoritmo Eficiente para la Construcción del Grafo de Dependencia de Control. Salvador V. Cavadini. Trabajo Final de Grado para obtener el Título de Ingeniero en Computación. Facultad de Matemática Aplicada. U.C.S.E. 2001.

“让我们构建一个编译器”是很棒的,但它有点过时了。(我并不是说这让它变得不那么有效。)

或者看看俚语。这类似于“让我们构建一个编译器”,但对于初学者来说是一个更好的资源。这是一个pdf教程,需要7步的方法来教你一个编译器。添加quora链接,因为它有各种各样的俚语端口的链接,在c++, Java和JS中,也有python和Java中的解释器,最初是用c#和。net平台编写的。