Comment by imwally
20 days ago
Anyone know a good resource for getting started writing a compiler? I'm not trying to write a new LLVM, but being a "software engineer" writing web-based APIs for a living is leaving me wanting more.
20 days ago
Anyone know a good resource for getting started writing a compiler? I'm not trying to write a new LLVM, but being a "software engineer" writing web-based APIs for a living is leaving me wanting more.
I've favorited a fair number of compiler discussions here. Some you may find useful, either for the linked content or the discussions therein:
- Writing a Compiler is Surprisingly Easy - https://craftinginterpreters.com
(But I'm just a kibitzer, I've never written anything more serious than a DSL in Perl.)
https://craftinginterpreters.com/
Traditionally you would start with the Dragon Book[1]. Another starting point is reading the documentation for Yacc (aka Bison) and Lex.
[1] https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniq...
The dragon book is a classic, and was a terrific resource thirty and forty years ago. Today there are many far better resources. Several listed adjacent to this one.
It’s focused on theory and very heavy on parsing. All of that is fine, but not especially useful for the hobbies.
There are several good suggestions in this thread already, but I think Nora Sandler's newish book (https://www.amazon.com/Writing-Compiler-Programming-Language...) is approachable and fun if you want a less academic approach.
I am currently going through that book. I recommend it with one caveat: you'll need to have written some interpreters before (Crafting Interpreters is a perfect starting point) because it expects you to already know some things like to how write a simple recursive decent parser.
I would highly recommend Wirth's Compiler Construction. Great, short book with a lot to say.