Reading Notes — The Dragon Book
Slaying the dragon
Why I’m reading itλ
Part of the allure of programming to me, is the ability to deconstruct abstractions to reveal the underlying truth about how computers and systems work. It just gives me this amazing rush of dopamine.
So like a heroin addict, this pursuit of dopamine led me to the Dragon Book.
I specifically wanted to learn about how lexer/parser generators work, and how to write one myself. This fascination was spurred by my increasing exposure to state machines in my work, thanks to xState.
Lexer/parser generators and regex engines are probably the coolest state machines. So why not learn how to build them?
How? A quick Google search tells us that Compilers: Principles, Techniques, and Tools (known mostly as the Dragon Book) is the best resource.
The problem is that I’ve always kind of been scared of this book. Usually when I’m afraid/overwhelmed by learning material, I identify what I’m afraid of and determine what I can do to alleviate these fears.
My primary fears were:
The book is huuuuge: it’s 1009 pages long
The book looks hard: the text’s academic/formal style makes it seem really unapproachable.
The dragon book is more of a reference guide, so it’s not really meant to be read cover-to-cover. So that alleviates fear 1. All I need to do is figure out what chapters I need to read and read them. Reading TAPL gave me the idea of building a tech tree to plot my learning path.
The only way to alleviate fear 2 is to actually just read the book. Most people (myself included) usually determine if a text is hard to read by skimming through it. Most of the time, a book that seems difficult to read is actually just difficult to skim, but actually reading it intently is not that bad.
If it’s still difficult after intently reading, it probably means I’m missing some prerequisite knowledge and will need to fill in those gaps first.
Thankfully the dragon book was actually not that hard to read intently. There were 1-2 concepts that I needed to Google supplementary material to understand, but it mostly was actually fun to read.
After relenquishing my fears, I followed my tech tree and implemented my own lexer and parser generator.
What I really liked about the book is that it each concept/algorithm/etc. is followed by an example demonstrating it in practice. Rather than bombarding you with solely theorems and definitions and proofs, you are presented with a practical example that helps you build your intuition on the topic.
I will say a slight issue I had with the text is that these academic books tend to sometimes have this vague writing style that sometimes makes it difficult to understand what the authors truly mean. This is alleviated with the examples section, but can be a bit annoying.
Now that I’ve tackled a part of the book, it’s given me confidence in exploring the rest of it. I’m particularly interested in learning about compiler optimizations.