views:

460

answers:

11

Summary for the impatient: I'm searching for good references on generating code for common language constructs but not parsing.

I am interested in programming languages and try to read the literature as much as possible. But most of them covers the topic in a functional and theoretical perspective that, I find them hard to understand let alone implement the ideas.

So the question is; Which resources do you suggest about programming language implementations that covers the topic in a more imperative and practical fashion?

For example, I find "The Implementation of Lua 5.0" paper very instructive.

Note that, I am not seeking articles about parsing or tokenizing.

+5  A: 

Here are a bunch of good textbooks:

Modern Compiler Implementation in Java (Tiger book) A.W. Appel Cambridge University Press, 1998 ISBN 0-52158-388-8 A textbook tutorial on compiler implementation, including techniques for many language features

Compilers: Principles, Techniques and Tools (Dragon book) Aho, Lam, Sethi and Ullman Addison-Wesley, 2006 ISBN 0321486811 The classic compilers textbook, although its front-end emphasis reflects its age.

Advanced Compiler Design and Implementation (Whale book) Steven Muchnick Morgan Kaufman Publishers, 1997 ISBN 1-55860-320-4 Essentially a recipe book of optimizations; very complete and suited for industrial practitioners and researchers.

Engineering a Compiler (Ark book) Keith D. Cooper, Linda Torczon Morgan Kaufman Publishers, 2003 ISBN 1-55860-698-X A modern classroom textbook, with increased emphasis on the back-end and implementation techniques.

Optimizing Compilers for Modern Architectures Randy Allen and Ken Kennedy Morgan Kaufman Publishers, 2001 ISBN 1-55860-286-0 A modern textbook that focuses on optimizations including parallelization and memory hierarchy optimizations.

Programming Languages Pragmatics Michael L. Scott Morgan Kaufmann Publishers, 2005 ISBN 0126339511

Adam Rosenfield
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-035Fall-2005/Readings/
artificialidiot
A: 

The Purple Dragon Book is the best ever.

TraumaPony
A: 

The Design and Evolution of C++ by Bjarne Stroustrup, which has fairly little code, but mostly discusses the trade-offs and other concerns in designing the language.

James Curran
A: 

Try to look at the LLVM project and their publications and tutorials.

zvrba
+1  A: 

I suggest playing with ANTLR. I used it awhile back and found it very easy to use.

kenny
I've got a tutorial on ANTLR 2.x at http://javadude.com/articles/antlrtut/index.html. I'm working to update it to ANTLR 3.x
Scott Stanchfield
+1  A: 

My favourite is "Building an Optimizing Compiler" by Robert Morgan. Very practical, covers static single assignment.

janm
A: 

There is another similar post here: http://stackoverflow.com/questions/41785/learning-resources-on-parsers-interpreters-and-compilers

jakobengblom2
That post also links to this one. Now we have a cyclical reference :-)
Parag
+1  A: 

Another hint: do not start digging into GCC; it is way too complicated. You want something more researchy and simple to start with, I would suggest looking into something like a Java compiler written in Java or the Erlang compilers written in Erlang.

jakobengblom2
+1  A: 

The "Dragon" and "Tiger" books (see above) are both excellent, though I find the "Tiger" (Appel) book a bit dense. I also quite like Modern Compiler Design by David Galles. As for tools and utilities to help you understand, I recommend taking a look at one or more of the following:

Alan
A: 

I like Compiler Construction by Nicolas Wirth, but maybe that's because learning (Turbo) Pascal was what made me decide to go into Computer Science.

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

+2  A: 

Supposedly (I read through it, but haven't done it), An Incremental Approach to Compiler Construction is excellent. It describes how the author teaches his compilers course.

From the abstract:

Compilers are perceived to be magical artifacts, carefully crafted by the wizards, and unfathomable by the mere mortals. Books on compilers are better described as wizard-talk: written by and for a clique of all-knowing practitioners. Real-life compilers are too complex to serve as an educational tool. And the gap between real-life compilers and the educational toy compilers is too wide. The novice compiler writer stands puzzled facing an impenetrable barrier, “better write an interpreter instead.”

The goal of this paper is to break that barrier. We show that building a compiler can be as easy as building an interpreter. The compiler we construct accepts a large subset of the Scheme programming language and produces assembly code for the Intel-x86 architecture, the dominant architecture of personal computing. The development of the compiler is broken into many small incremental steps. Every step yields a fully working compiler for a progressively expanding subset of Scheme. Every compiler step produces real assembly code that can be assembled then executed directly by the hardware. We assume that the reader is familiar with the basic computer architecture: its components and execution model. Detailed knowledge of the Intel-x86 architecture is not required.

The development of the compiler is described in detail in an extended tutorial. Supporting material for the tutorial such as an automated testing facility coupled with a comprehensive test suite are provided with the tutorial. It is our hope that current and future implementors of Scheme find in this paper the motivation for developing high-performance compilers and the means for achieving that goal.

Paul Biggar