
Ask HN: Best book about compilers? - pipu
I would like to grab a book on compilers but am not sure which one to choose.<p>The Dragon book (Compilers: Principles, Techniques, and Tools) is the one that gets recommended everywhere but that doesn&#x27;t always mean it&#x27;s the best. I find that many people recommend books they&#x27;ve actually not read and&#x2F;or they haven&#x27;t read anything else on the subject which makes it a bit tough to say the one they&#x27;re familiar with is the best.<p>Some have said the dragon book is unbalanced in content and for instance Modern Compiler Implementation in ML is better in that.<p>What is your opinion? Can you recommend some book over another one?<p>Also: I&#x27;m not sure if a 800 page brick is the best to get yourself familiar with ... anything(?). I&#x27;m most certainly sure the book I&#x27;m looking for doesn&#x27;t have to cover every tiny little detail that could be useful to know every 0.000001 % of time.<p>Thanks!
======
kjksf
I doubt people who actually do write compilers would get much of use of any
book out there.

There are 2 main tasks a compiler does:

* parsing * optimized code generation

While nominally parsing is covered by books and there's loads of theory on it,
production compilers (gcc, clang, Go, swift) pretty much always end up with
hand-written recursive-descent parser, which are a lot work but their
structure is rather simple.

Code generation is universally done by converting to SSA and then writing
optimization passes on top of that. Again, lots of work and lots of
optimization rules, but nothing earth shattering conceptually. Read up on SSA
and study existing code like
[https://github.com/golang/go/tree/master/src/cmd/compile/int...](https://github.com/golang/go/tree/master/src/cmd/compile/internal/ssa)
for real-life optimization.

Then there's linker stuff like generating pe/elf/mach-o executables,
generating symbols etc., which isn't covered in books but there's
documentation on-line on all those subjects and you can study existing code
like
[https://github.com/golang/go/tree/master/src/cmd/link/intern...](https://github.com/golang/go/tree/master/src/cmd/link/internal/ld)

------
joe_loser
The book "Engineering a Compiler" ([https://www.amazon.com/Engineering-
Compiler-Second-Keith-Coo...](https://www.amazon.com/Engineering-Compiler-
Second-Keith-Cooper/dp/012088478X)) is a good resource and reference; I keep
it on my desk at work. Like other compiler books, it falls short in meeting
all practical application purposes and does great with theory. Ideally, this
book should be combined with looking at modern compiler implementations.

------
brudgers
I'm not sure it is the best, but it is clearly an alternative to the Dragon
book.

[https://compilers.iecc.com/crenshaw/](https://compilers.iecc.com/crenshaw/)

------
zerr
Is the dragon book really recommended nowadays? I don't think so, especially
for starters.

~~~
hackermailman
CMU still uses the dragon book 2ed for their grad level compilers course
[https://www.cs.cmu.edu/~15745/syllabus.html](https://www.cs.cmu.edu/~15745/syllabus.html)
and Andrew Appel's compiler book for the undergrad course.

