What are good resources to compile?

Summary for the impatient: I am looking for good code generation links for general language constructs, but not parsing.

I am interested in programming languages ​​and try to read literature as much as possible. But most of them cover the topic in a functional and theoretical perspective, which, I think, is difficult to understand, not to mention the implementation of ideas.

So the question is: What resources do you propose about programming language implementations that touch on this topic more urgently and practically?

For example, I find the article “Implementing Lua 5.0” very instructive.

Please note that I am not looking for articles about parsing or tokening.

+4
source share
10 answers

Here are a bunch of good tutorials:

Modern Implementation of the Compiler in Java (Tiger Book) AW Appel Cambridge University Press, 1998 ISBN 0-52158-388-8 Tutorial on the implementation of the compiler, including methods for many language functions.

Compilers: principles, methods and tools (book of dragons) by Aho, Lam, Seti and Ullman Addison-Wesley, 2006 ISBN 0321486811 A classic compiler textbook, although its external level reflects its age.

Development and implementation of an extended compiler (book of whales) Stephen Muchnik Morgan Kaufman Publishing House, 1997 ISBN 1-55860-320-4 In fact, an optimization recipe book; very complete and suitable for industrial practitioners and researchers.

Compiler development (Ark book) Kate D. Cooper, Linda Torchon Publishing house Morgan Kaufman, 2003 ISBN 1-55860-698-X A modern textbook on academic subjects with increased attention to working methods and implementation.

Compiler Optimization for Modern Architectures Randy Allen and Ken Kennedy Morgan Kaufman Publishing House, 2001 ISBN 1-55860-286-0 A modern textbook on optimization, including optimization of the parallelization hierarchy and memory.

Programming Languages ​​Pragmatics Michael L. Scott Publishing House Morgan Kaufmann, 2005 ISBN 0126339511

+9
source

Presumably (I read it but didn't), the incremental approach to building a compiler is excellent. It describes how the author teaches a course for his compilers.

From the abstract:

Compilers are perceived as magical artifacts carefully crafted by wizards and incomprehensible to mere mortals. Books about compilers are better described as "magic talk": they are written for the clique of all-knowing practitioners. Real compilers are too complex to serve as a training tool. And the gap between real compilers and compilers of educational toys is too wide. The newbie compiler is looking puzzled at the impenetrable barrier, "better write a translator."

The purpose of this article is to overcome this barrier. We show that creating a compiler can be as simple as building an interpreter. The compiler we created accepts a large subset of the Schema programming language and creates assembly code for the Intel-x86 architecture, the dominant personal computer architecture. Compiler development is divided into several small stages. Each step provides a fully working compiler for a gradually expanding subset of the Schema. Each step of the compiler creates real assembly code that can be assembled and then executed directly by hardware. We assume that the reader is familiar with basic computer architecture: its components and execution model. Detailed knowledge of the Intel-x86 architecture is not required.

Compiler development is described in detail in an extended tutorial. The training manual contains supporting material for the training manual, for example, automatic testing tools, as well as a comprehensive set of tests. We hope that current and future developers of the Scheme will find in this article the motivation for developing high-performance compilers and tools to achieve this goal.

+3
source

I suggest playing with ANTLR . I used it a while ago and found it very easy to use.

+2
source

The Dragon and Tiger books (see above) are both excellent, although I find the Tiger (Appel) book a little tight. I also really like the modern design of the compiler by David Gulles. As for tools and utilities that will help you understand, I recommend taking a look at one or more of the following:

+2
source

My favorite is Robert Morgan's Creation of an Optimization Compiler. Very practical, covers static single use.

+1
source

Another hint: don't start digging into GCC; it's too complicated. You want to start something more scientific and simple, I would suggest learning something like a Java compiler written in Java, or Erlang compilers written in Erlang.

+1
source

Design and evolution of C ++ by Bjarne Stroustrup, which has quite a bit of code, but mainly discusses trade-offs and other issues in language design.

0
source

Try looking at the LLVM project and their publications and tutorials.

0
source

I like Nicolas Wirth's Compiler Construction, but maybe because the training (Turbo) of Pascal was what made me decide to go to Computer Science.

http://www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf

0
source

The book "Purple Dragon" is the best of all.

-1
source

Source: https://habr.com/ru/post/1277317/


All Articles