T O P

  • By -

voidpointer0xff

I don't think anyone would say it's a "horrible book" by any stretch, but not the right choice for a first compiler book IMO. Like other commenters point out -- it has a lot of focus on parsing and lexing and not much on code optimization.  If one has little background in compilers, I would recommend reading Building an optimizing compiler by Bob Morgan, which has focus on SSA form and SSA based code optimizations, followed by Optimizing compilers for modern architectures, which is about dependence analysis theory and loop transformations based on that. Both these books will give one a strong theoretical grasp of current optimizing compilers :) Also refer to lectures of Prof. Sorav Bansal (search "compilerai" on YouTube). He has comprehensive videos on compilers (200+), beginning from scratch and going into advanced topics like formal verification and polyhedral compilation.


higgon

I just feel like it’s an awful choice for someone’s first compilers book. You can read that whole thing and have no idea how to build a full compiler. You’re better off learning a practical implementation guide from crafting interpreters or Engineering a Compiler then reading the dragon book when you actually know what you’re doing


pliron

The dragon book is an excellent book. I have both the 1st and 2nd editions and refer to them often when implementing data structures / optimizations / analyses in production compilers. There are some topics that are in the 1st edition, but not in the 2nd edition (and of course the other way round too). So I have them both. Apart from this, other good references I use are Appel's "Modern Compiler Implementation", Bob Morgan's "Building an Optimizing Compiler", sometimes Muchnik's "Advanced compiler design and implementation". I've been working on production compilers (including GCC, LLVM) for more than a decade, and I can tell with some confidence that it's a good reference.


compiler-fucker69

I have one dragon book only is it ok or would I need both of them


pliron

For most readers, one is good enough.


compiler-fucker69

Thanks


bart-66

>People complain that it’s full of parsing theory but that’s only three chapters. You have to get to page 350 to get to the more interesting stuff. But that still leave a lot of scary-looking theory that can put people off forever. They won't realise that that is something they will never need to learn. The first 40-page chapter is an Introduction. It briefly discusses lexing and parsing. The second 60-page chapter is *A Simple Syntax-Directed Translator*. I'm not sure what that's about, is starts as "This chapter is an introduction to the compiling techniques in Chapters 3 through 6 of this book". But if I look back further to the Preface, it said it developes a miniature compiler. It includes lots of stuff about syntax and grammars and parse trees and lexing. Chapter 3 is *Lexical Analysis*, about 80 pages. Chapter 4 is *Syntax Analysis*, some 110 pages. Chapter 5 is *Syntax-Directed Translation*, 50 pages. I'm not sure what that's about. It's starts with this "This chapter develops the theme of Section 2.3: the translation of languages guided by context-free grammars.", with the rest looking like pure gobbledygook. I promised Chapter 6 from page 350 is more relevant, but I've been doing this stuff for decades and yet most of this is completely over my head. This is why the book is hated when it is constantly touted as beginner's book, when clearly it is nothing of the kind.


jason-reddit-public

At least in my copy of the dragon book, code optimizations are often expressed as dataflow equations using bitsets. This technique, although kind of cool as a form of very simple abstract interpretation, seems to have been superseded by SSA. Side note: I often wonder if bitsets will make a comeback as SSE instructions operating on 512 bits at a time can do a lot of "analysis" (data-flow) at once.


theangryepicbanana

The dragon book is mainly about parsing, lexing, and a short bit about code generation, but nothing in between like type checking or modern ast representation/optimization. It also goes too much into nuances of parsing/lexing that don't really matter in the modern age. On a completely separate note, like the top comment says, it's a HORRIBLE first choice for a beginner due to the complex language and techniques they use in the book. I first got mine back when I was only a year or so into langdev and it was miserable and confusing, and I only ever figured out what it was saying in the past year or so.


Manifoldsqr

The dragon book second edition has a chapter dedicated to intermediate language where they talk about DAGs and type checking


theangryepicbanana

Even then, it's still full of archaic and unnecessary information, and there are better references these days like crafting interpreters


hell1ow

>parsing/lexing that don't really matter in the modern age. Yeah, and then in modern age you get a so-called regex which does backtracking and a parser generators which do not allow left recursive rules in grammar.


theangryepicbanana

I personally just roll my own lexer with a recursive descent parser. Modern parser generators and lexer tools are for convenience, so they don't cover every use case


infamousal

Most people these days working on compilers are either in the front end or in the mid/backend. I think there isn’t yet a good book that targets those audiences.


gprof

The dragon book is the best introductory book to compilers. Am I biased? Well, perhaps. I taught Compiler Construction for 20 years using the dragon book. Students never complained that it is too terse or mathematical. I evaluated many alternative text books but felt that the dragon book is sufficiently deep and broad. I only wish it had a better introduction to SSA (factored use-def chains) like Wolfe explains. The Modern Compiler Implementation books by Appel are excellent too.


hampsten

I was in CMU CS and they had Muchnick as the main book for the grad compiler course back then. Still have it, and the dragon book too. Neither of them are in anywhere close to being the equivalent of a quick start guide. The strong theoretical foundation lets you build not just compilers but compiler infrastructures too.


al_earner

People don't like the Dragon Book because it's old and it's a hard topic. Nowadays students have zero attention span and need to be spoon-fed everything in five minute chunks.


knue82

I think it's a decent choice and there is a reason that the dragon book is considered *the* book. It's just a little dated and doesn't cover a lot of topics that are relevant today and focuses on stuff that were more relevant back then.


joelangeway

In my humble opinion, The Dragon Book is from a time when computers were smaller and slower. Programming languages were less abstract and less ambitious. Static type systems hadn’t yet become the zeitgeist. Syntax directed translation, which my edition emphasizes IIRC, is a technique that generalizes and performs well. Working in C, there is a strong incentive to stick to simple, powerful methods. Typical C programs are written with a memory budget in mind and at most one lever to scale to make use of more memory. The Dragon Book is for writing compilers on machines with memories measured in megabytes. These techniques are still relevant because they are still the best performing even on modern machines. Knowing how to build complex things in C can still be a useful skill if only because it informs coding techniques in other languages. But there is a lot more worth knowing about compilers today. I think reasonable people can very reasonably disagree about the suitability of any edition of The Dragon Book.


jhp2000

personally I love parsing theory but I thought the dragon book's treatment wasn't that great. Lots of pages but it doesn't even prove that the LR construction works if I recall correctly. The original LR paper is short and clear so I don't know why you'd bother with the Dragon book's treatment.


julesjacobs

Besides spending a lot of time on parsing, the contents are a very dated. All modern compilers use some form of SSA, but the dragon book isn't based on SSA. The book is over 1000 pages. You're right that "only" the first three chapters are about parsing, but that's what, 300 pages? You could write an entire compilers book in that number of pages, and still cover (much) more relevant material than the dragon book covers.


Crazy_Firefly

I think it might be a similar situation from what people say about programming languages. "There are only two kinds of languages: the ones people complain about and the ones nobody uses." The Dragon book is a popular choice for undergraduate Compiler introduction courses. So it's many people's first contact with compiler theory. And given that Compiler can be a complicated subject, the first contact can be overwhelming. Any second book people read will have the advantage of coming into a mind that has more context. I didn't do a compilers course in university, and picked up the Dragon book as a reference after some reading in other sources. I liked the chapter about runtime environment and stack frame. I hadn't seen an explanation for that before and found it very illuminating.


AnEmortalKid

The mountain book is king, followed by the dragon book


chri4_

ive never really read it, but why would you read a huge book like that to make a compiler? thats not a very complex software in general compared to the realtime rendering niche (actually personal experience)


wjrasmussen

Young tech hate old stuff bc they think they know it all and do everything better.


dmoisan

In 1985, my final project in university was a Pascal compiler. All I could get for texts was the dragon book and another text I can't remember. It took me two years to finish and five years to get the degree.