logoalt Hacker News

projektfutoday at 1:21 PM7 repliesview on HN

The dragon book almost convinced me never to try to write a compiler. I don't know why people recommend it. I guess you're a lot smarter than I am.

There are some excellent books out there. In its own way, the dragon book is excellent, but it is a terrible starting place.

Here are a bunch of references from the same vintage as OP. I recommend starting with a book that actually walks through the process of building a compiler and doesn't spend its time exclusively with theory.

https://news.ycombinator.com/item?id=136875


Replies

rangerelftoday at 4:08 PM

You're not the only one. In college I took a compilers course and we used the dragon book, to me it sucked the joy out of the magical concept of making a compiler.

Some years later I (re-) discovered Forth, and I thought "why not?" and built my own forth in 32-bit Intel assembly, _that_ brought back the wonder and "magical" feeling of compilers again. All in less than 4KB.

I guess I wasn't the right audience for the dragon book.

pjmlptoday at 7:26 PM

It was a product of its time I guess, much better ones from similar vintage,

The Tiger book (with C, Standard ML, and Java variants)

https://www.cs.princeton.edu/~appel/modern/

Compiler Design in C (freely available nowadays, beware this is between K&R C and C89)

https://holub.com/compiler/

lcc, A Retargetable Compiler for ANSI C

https://drh.github.io/lcc/

Or if one wants to go with more clever stuff,

Compiling with Continuations

Lisp in Small Pieces

show 1 reply
randomNumber7today at 4:19 PM

Imho the problem is the fixation on parser generators and BNF. It's just a lot easier to write a recursive descent parser than to figure out the correct BNF for anything other than a toy language with horrible syntax.

show 1 reply
_falsetoday at 6:05 PM

Great thread. If you have 1 hour to get started, I recommend opening Engineering a Compiler and studying Static Single-Assignment (SSA) from ch 9.3.

The book is famous for its SSA treatment. Chapters 1-8 are not required to understand SSA. This allows you to walk away with a clear win. Refer to 9.2 if you're struggling with dominance + liveness.

http://www.r-5.org/files/books/computers/compilers/writing/K...

show 1 reply
wglbtoday at 2:15 PM

When I was professionally writing a compiler professionally (see https://ciex-software.com/intro-to-compilers.html) the Dragon book was the second book that I read. I found it very helpful. That was the first Dragon book. I got the second one later. I would have been ok to start with the Dragon book--the Compiler Generator book was a harder study.

saidnooneevertoday at 2:07 PM

the dragon book is how to write a production grade thing i guess. it has all the interesting concepts very elaborated on which is great but it dives quickly into things that can clutter a project if its just for fun..

show 1 reply
tovejtoday at 1:31 PM

I started with the dragon book, and I found it to be a good introductory text.

A lot of people say the dragon book is difficult, so I suppose there must be something there. But I don't see what it is, I thought it was quite accessible.

I'm curious, what parts/aspects of the dragon book make it difficult to start with?

show 1 reply