
Modern compiler implementation in ML
by Andrew W. Appel · first published 1997
68mentions
24recommended by
50HN commenters
2009–2024first – last mentioned
48% recommend50% neutral2% critical
Why HN recommends it
Practical, production-minded intro to compiler construction, from parsing through code generation, optimization and runtime topics like garbage collection. Preferred over the Dragon Book; ML makes the code easy to read.
Summarised by Claude from recommending comments
Affiliate links. As an Amazon Associate I earn from qualifying purchases.







…21st century so many times on HN that I'm not going to comment on it's usefulness. (Search if interested) But, for those interested, I highly recommend Engineering a Compiler by Cooper and Torczon OR Modern Compiler Implementation in ML by Appel. I've read all three and would only recommend the dragon book to someone very interested in the subject.
on “An Intro to Compilers” ↗…suggest that before the Nanopass paper, really. After those, I recommend Niklaus Wirth's _Compiler Construction_ (http://www.inf.ethz.ch/personal/wirth/books/CompilerConstruc...) and Andrew Appel's _Modern Compiler Implementation in ML_ for follow-up, in that order. Wirth's book is a quick read, about on par with Crenshaw's. Appel's is more in-depth. Another comment, linking several HN compiler threads: http://news.ycombinator.com/item?id=1922002
on “Want to Write a Compiler? Just Read These Two Papers.” ↗Andrew Appel's _Modern Compiler Implementation in ML_ is probably what you want. (http://www.amazon.com/Modern-Compiler-Implementation-Andrew-...) While it uses SML, it's not hard to follow if you use OCaml, and the bibliography / references are also quite…
on “Writing Your Own Toy Compiler Using Flex, Bison and LLVM” ↗The classic is the "Dragon Book": http://www.amazon.com/Compilers-Principles-Techniques-Alfred... I'm also partial to Appel's "Modern Compiler Implementation in ML", because it goes into more detail about techniques for compiling functional languages: http://www.amazon.com/Modern-Compiler-Implementation-Andrew-...
on “Google Closure: How not to write Javascript” ↗I found Appel's _Modern Compiler Implementation in ML_ to be better-suited to self study, and more modern. I've used OCaml but not SML, and didn't have any problem following it.
on “Books Programmers Don't Really Read” ↗Appel's _Modern Compiler Implementation in ML_ is a good overview. It uses SML, but I've only used OCaml and haven't had any problems following it. _Essentials of Programming Languages_ (EoPL) is a great book about writing interpreters in Scheme,…
on “Rich Programmer Food” ↗Oops, I downvoted you when I meant to upvote. There is probably another incarnation or three before the one you linked, too. I'd recommend Appel's "Modern Compiler Implementation in ML" over the dragon book.
on “Learning to write a compiler” ↗…free English translation is online at http://caml.inria.fr/pub/docs/oreilly-book/html/index.html). It covers a slightly older version of the language, but that mostly impacts libraries. Andrew Appel's _Modern Compiler Implementation in ML_ and _Compiling with Continuations_ are both great compiler books, which happen to use SML for the code. Joshua Smith's _Practical OCaml_ is bad. Really bad. I was shocked. Avoid. Chris Okasaki's _Purely…
on “The 3 Programming Languages you need to Know” ↗Yes, among others. Briefly: Read that, then Appel's _Modern Compiler Implementation in ML_, then chase whatever interests you in the bibliography and on citeseer. See also: http://news.ycombinator.com/item?id=1822515 (first) http://news.ycombinator.com/item?id=1820858 (parsing) http://news.ycombinator.com/item?id=1608752…
on “Algorithms and Data Structures by N. Wirth [pdf]” ↗…factors out some complexity - only the lexer needs to care about things like whitespace, for example. While most compiler textbooks cover lexing and parsing, I particularly recommend Andrew Appel's _Modern Compiler Implementation in ML_ and Niklaus Wirth's _Compiler Construction_ (free online, http://www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf). More recommendations on learning parsing here: http://news.ycombinator.com/item?id=1820858
on “Efficiency of regular expressions” ↗…can also get better compiler texts, these days. I recommend starting with Niklaus Wirth's _Compiler Construction_ (http://www.inf.ethz.ch/personal/wirth/books/CompilerConstruc...), then Andrew Appel's _Modern Compiler Implementation in ML_. I have a comment linking together several threads of compiler-related advice on HN here: http://news.ycombinator.com/item?id=1922002.
…you looking for an alternative to emitting C or to using C as the implementation language of the compiler? I'm not totally sure what you're after, and I'm a compiler noob, but I've been enjoying Appel's Modern Compiler Implementation in ML, which uses SML as the implementation language and emits RISC machine code or assembly (I think, I haven't actually gotten that far). I don't know how suitable it would be as a stepping stone to forking…
on “PHP Sucks But I Like It” ↗Not sure if there are any books around LLVM or gcc, but there is a lot of up to date texts. Grune at al., "Modern Compiler Design", Appel, "Modern Compiler Implementation in ML", and many more. P.S. Because of a slow-ban, adding another one to this answer. This is the best source on SSA: http://www.cri.ensmp.fr/people/pop/papers/2006-12-thesis.pdf
on “How I wrote a self-hosting C compiler in 40 days” ↗My three favorite books on compilers (in no particular order) are: * Engineering a Compiler: https://www.amazon.com/Engineering-Compiler-Second-Keith-Coo... * Modern Compiler Implementation in ML: https://www.cs.princeton.edu/~appel/modern/ml/ * Compiling with Continuations: https://www.amazon.com/Compiling-Continuations-Andrew-W-Appe...
on “Programming books you might want to consider reading” ↗Appel's Modern compiler implementation in ML is really good, as both an introduction to compilers and some detail on implementing the runtime i.e. garbage collection. There are versions for C and Java, but ML is much easier to read in a book. If…
on “Resources on creating programming languages” ↗