Hacker News new | past | comments | ask | show | jobs | submit login
Engineering a Compiler, 2nd Edition is out (elsevierdirect.com)
116 points by mattyb on Feb 9, 2011 | hide | past | favorite | 33 comments



I repeat my criticism: I reported an error in the book twice to the email address that was specified for "errata," and never heard anything back:

http://news.ycombinator.com/item?id=1643787

I would hope that they have corrected this error in this version of the book, but their non-response to my report does not give me hope.


I've not read the book so I'm not sure how good it is. However, at times authors don't reply but they do include your name with acknowledgment so did you check the new edition? But if that didn't happen, then I totally agree with your sentiment.


They have a list of errata for the first edition, and it makes no mention of my correction:

http://www.cs.rice.edu/~keith/Errata.html


I love this book! I have (or had) about 7 compiler books, and this was always my favourite (another notable is Programming Language Pragmatics, and also perhaps Modern Compiler Design in X).

For beginners, this book rocks. It's readable, very well written, and very easy to follow. For intermediates, it has tons of interesting asides and anecdotes.

(All this applies to the first edition - I haven't read the second).

Finally, many people recommend the Dragon Book; I really really could not recommend it less. Buy Engineering a Compiler instead - there is really no comparison.


This is a pretty good book (from v1) and v2 looks more complete. I do like the writing in the Dragon Book, but the latest edition missed some things. Like the fact that SSA isn't used extensively is a mistake.

One thing that does appear missing from both books are some topics that should be of more interest... like compiling closures (and while it may only take a second of reflection to think of how to do it... its nice to have a textbook that also details it and any tricky corners that aren't obvious).


Could you please suggest a list of books to read in sequence to learn about building compilers? Thanks.


I'm not sure about reading the books in sequence (I haven't tried it), and after a short period you'll probably find yourself referring to the papers they reference. I've heard good things about this as a first step:

http://news.ycombinator.com/item?id=1408241

Otherwise, I'd recommend Engineering a Compiler, or Modern Compiler Design in X by Appel (where X is one of the languages in which the book is offered).



Another, but free: Compiler Construction (http://www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf)


Wirth is a bit out of date imho


I don't really know, but the book seems pretty basic. I would be surprised if any of the compiler ideas it covers were actually obsolete. They might be simplifications, but they are likely still useful to someone new to the subject. The concrete elements of the book definitely aren't shiny new. The example self-hosting compiler is implemented in a Pascal-like language called Oberon and targets a virtual RISC architecture. But I think the essential ideas behind compilers are the same today as they were fifteen years ago.


I agree that it is the best book on compilers for beginners. I think that parsing using a recursive descent parser for LL grammars with attributed grammars teaches you the most basic and important things (such that one is able to design and parse a nice DSL.)

Having said that the book's major draw back is that is "soft" on the major topics of today: optimizations. The book is very frontend centered and mentions some possible optimizations in the final chapter--no implementations given. Hence, while I always recommend this book as the first go-to book, interested compiler programmers have to find supplemental material elsewhere. (I love M. Scott's "Programming Language Pragmatics", respect Grune, Bal, Jacobs and Langendoen's "Modern Compiler Design", consult Muchnick's "Advanced Compiler Design and Implementation".)

Topic-wise, supplemental material to Wirth's CC-book, I suggest: LR-parsing (yacc) and in-depth study of instruction selection ([i]burg) and register-allocation (graph coloring) for important backend optimizations. I think that gives a firm understanding of compilers, suitable for further study (such as Muchnick "Advanced Compiler Design and Implemetation" 1997 or Morgan "Building an Optimizing Compiler" 1998.)


The Wirth book gives a fairly quick overview that other compiler books can expand on. If you started with (say) the dragon book, you'll be wading through 200 pages about automata theory and parsing algorithms before you even get to anything else. Wirth provides a twenty-page overview, recommends starting with recursive descent parsing, and just moves on to the next issue.

I recommend starting with the Wirth book, then Andrew Appel's _Modern Compiler Implementation in ML_. And don't forget about the exercises!


I just want to second the antlr reference book. Even though it is specific to framework, it can still be used as a great, readable introduction to compilers.


If you want to look at a real-world compiler, check out the Go suite of "gc" compilers, which are mostly written by Ken Thompson. The source for the Go ARM compiler is at http://golang.org/src/cmd/5g/, or you you can browse the entire Go source tree at http://code.google.com/p/go/source/browse.

The Go compilers are very fast. For most of the code I've developed (several hundred lines per package) I rarely have to wait more than 0.1 seconds to compile and link on my 2.4GHz i5.


Agreed, go rocks :)

Keep in mind that a lot of the logic is shared between backends, so check out http://code.google.com/p/go/source/browse/src/cmd/gc for the core stuff too.


Edit: Ignore this entire comment. I've been reading a different "engineering a compiler" subtitled, "vax-11 code generation and optimization". Which, as I explained is very interesting, but certainly not really for a beginner. Now I just need to get a copy of the actual "Engineering a Compiler" everyone has recommended I read. :-)

I've just started reading this book, (older edition), after reading many recommendations that it would be a good place to start for beginners. I find it is an enjoyable read, but I don't really feel like I'm learning how to write a compiler. Much of the text seems devoted to the experience of wrestling with the restrictions of the technology of the day, (e.g. compile times were 12-24 hours because they had to wait for tapes generated by one half of the compiler at one location to be couriered to another location to be finished). I find this fascinating, but it's not really helping me learn to write a compiler. On top of that the solution and code is very close to the metal, which again I find to be fascinating but not incredibly educational.

I want to write a templating language in Haskell as an exercise to learn Haskell and get my feet wet with compilers. What's a good book for me?


I'm in the same situation and I just ordered a copy of:

http://www.pragprog.com/titles/tpdsl/language-implementation...


It would be nice to learn about new compiler internals. I wonder though, how many of us would need to work day to day on a compiling language (as comparing to intercepted or JIT languages.)

BTW, why not getting that @ amazon? At least you get 20% of in the US (but only get the book by March)

(The worst plug here for my own amazon link, you are warned, please don't vote this down just for the link: http://amzn.to/fpNazO)


I work day to day on a compiler backend. It's used in an emulator (as a JIT), with the JVM (as a JIT), and with various static languages (as a static compiler).

You'd be surprised at the similarity between a JIT compiler and a static compiler with profiler feedback. Much of the optimizations are the same, and a lot of the code generation is the same. In fact, the biggest difference is just that there's a VM for jitted languages, but just a runtime for (most of) the static languages.

I will say however, that this book looks pretty decent, looking through the table of contents shows that it's not missing that many optimization concepts and is a good start for understanding how your compiler (JIT or otherwise) works. Understanding how your compiler works is a big step towards mastering a language.


Isn't much of the engineering of a compiler the same, regardless if machine code or intermediate VM code is emitted?


Just outputting something isn't particularly different whether it occurs at runtime or "compile" time. However, if you want to know how to execute Python efficiently that's a very different topic than how to execute C efficiently.


If anything has to be language/platform/framework specific, it would not be at the compiler level. There are just some many things that could affect the performance of some code, it would be naïve to simply looking at things on compiler level.


I was speaking more generically about a highly dynamic vs a highly static language, using Python as an example. The same comment applies to Ruby or Javascript.


Yes you are right. So in general we should read this book.


Maybe sibling is referring to an aspect of Python I'm not aware of (there are probably many), but much of the book (or at least the first edition) is language-agnostic. Tasks are pretty well partitioned into front-end, optimization, and back-end sections (further, really), with the idea that each segment of the compiler doesn't have to worry much about other segments' tasks (e.g. code shape is not the concern of the parser).


No problem regarding your own amazon link, it's convenient. But there is no ebook option on Amazon though. The article link has an ebook version which is while why I will buy it there.


I like the ebook part, but I think I'll pass; they appear to be using their own format, and it's DRM'd: http://www.elsevierdirect.com/article.jsp?pageid=8258


Plus it's a $65 ebook, I know it's quiet specialized but that's going to turn away anyone who has a passing interest in compilers pretty quickly.


Like me. I may try to pick it up used (hello, zero money to publisher for re-sale. Well, price production-cost-free stuff cheaper!)


Yep, that's one reason I submitted this URL. The other is that it's available now from Elsevier, whereas Amazon has the release date listed as March 1st.


But the interpreting process often is a form of compilation - e.g. many interpreters compile source to bytecode and interpret the bytecode - to say nothing of JIT, which after all stands for just-in-time compilation!

Compiler design I think will always be a vital field. The LLVM project I think shows the direction we are headed - with more and more detailed bytecode to allow for better optimization before a 2nd pass compiles down to machine code.


I must admit that Elsevier is such a red rag for me that I did not even consider visiting that site, even though I find the topic interesting.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: