I second that recommendation, with a preemptive shush to anyone was about to whine that it spends so much time covering parser generators. Those algorithms may be old hat, but they're nonetheless enlightening once you understand why they work. I do wish they covered optimization in more depth, though.
FROM THE HN SHELF
Compilers: Principles, Techniques, and Tools
Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman
Computing · A BOOKTypographic jacket · original cover not fetched
FROM THE SHARED SHELF · 2006–2026 SAMPLE
Compilers: Principles, Techniques, and Tools
Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman
7 readers recommend it across 1 discussion
Topics are model-inferred labels.
Keep it on your reading list
THE WORD OF MOUTH
What made it worth passing on?
Original Hacker News comments, in the readers’ own words.
I would say that there are two important things to consider: 1. Understanding how a compiler works without getting bogged down by programming language details - This means that you should try and look at compilers written in Standard ML or Ocaml (my favorite), since that would be much easier to follow. For example -- a datatype can be much more succinctly expressed as type any_value = Int | String | Float rather than across 4 classes (as in the Java case). 2. Start small, and understand it in chunks. For these, a lot of web based resources are ideal. For example, to understand regular expressions, it would be nice if you were able to visualize them, and play around with them visually - http://osteele.com/archives/2006/02/reanimator I would also look at simple examples of interpreters, and build up from that, looking at examples of toy compilers: http://min-caml.sourceforge.net/index-e.html These will help, of course alongside a book like Appel's or the Dragon Book.
Also recommended in this reply
The fundamental book to read would be "Introduction to Automata Theory, Languages, and Computation" ( http://www.amazon.com/Introduction-Automata-Theory-Languages... (http://www.amazon.com/Introduction-Automata-Theory-Languages-Computation/dp/0321462254/)) Then proceed to Dragonbook. After finishing Dragonbook, you might like this Linkers and loaders (http://www.amazon.com/Linkers-Kaufmann-Software-Engineering-... (http://www.amazon.com/Linkers-Kaufmann-Software-Engineering-Programming/dp/1558604960)) In general follow this guy Jeff Ullman and you would be good(http://infolab.stanford.edu/~ullman/)
Also recommended in this reply
Modern Compiler Implementation by Andrew-Appel is a very good introduction book for people to get started on doing a compiler. And if you want to be more pragmatic, here is a shorter one: http://www.cl.cam.ac.uk/teaching/2004/CompConstr/NEJ/report.... (http://www.cl.cam.ac.uk/teaching/2004/CompConstr/NEJ/report.pdf) The dragon book is a MUST for compiler researcher and people who are serious on compiler, but it is hard to follow, and I do not recommend it as your first compiler book. For ruby, you can take a look of the xruby compiler I did: http://xruby.googlecode.com (google code's server has some problem now, you may have to wait for a while)
Also recommended in this reply
another (more interactive) option might be to pickup a standard compilers text-book e.g aho-ullman / aho-ullman-sethi and follow the intro-compilers course-work available at any of the universities (e.g. stanford). work through the exercises i.e. hack, hack, hack ! at least at stanford, you will end up writing a small compiler for a toy java like language. kind of nice. from there you can go onto more mature stuff e.g. llvm. edit: it would be even more fun, if you could take the tests too (within stipulated times ofcourse).
This is what is commonly refered to as "the dragon book". http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniqu... (http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools) But that may be too massive for what you are looking for. I found that Crockfords essay http://javascript.crockford.com/tdop/tdop.html really helps if you know javascript. And reading something like tinypy http://www.philhassey.com/blog/2008/02/28/tinypy-10-mit-lice... (http://www.philhassey.com/blog/2008/02/28/tinypy-10-mit-license-and-swell-opengl-demo/) may help. Also not necessarily a compiler book, but The Little Schemer does have you building a basic scheme interpreter at the end of the book.
Also recommended in this reply
The dragon book is Aho, Sethi, & Ullman. If you look through modern string search algorithm implementation, for example, the number of hits for Aho is up there with Knuth. Not that string searching has an awful lot to do with compilation, more lexing and parsing, but still. Aho and Ullman are pillars and the book is sort of the bible. http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniqu... (http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools) It's been updated to cover parallelization and other topics that were considered specialties when it was originally written. I have an older copy and am now wondering whether it mightn't be fun to trade up. We'll see. Have you played with ANTLR? That's a neat tool. The Ragel state machine compiler is a fun toy, as well.