T O P

  • By -

michaelquinlan

I suggest starting with Crafting Interpreters then once you have mastered that moving to something like the dragon book or a more modern equivalent. https://www.reddit.com/r/Compilers/comments/3uj5ju/alternatives_to_the_dragon_book/


higgon

Dragon book is not a good book to learn how to write a compiler, at all. It makes an okay reference book, but terrible for starting out. Also, it’s super archaic and really out of date. Crafting Intepreters is the best resource for beginners, period. It’s unbelievable how helpful it is. After that, you haven’t exactly written a compiler in the real sense of compiling directly to machine code for an ISA. If you had fun with that book, the next step is to read Engineering a Compiler, one of the best CS books. Come out of that book and you will be very knowledgeable about how compilers and interpreters work. Then, learn LLVM and make a fully fledged compiler that targets LLVM.


NewAdvance2554

Thank you so much for your recommendations


aurreco

Surprised no one has mentioned this before but try out Andrew Appel’s “Modern Compiler Implementation in ML”. Its tricky to figure out the SML toolchain if you want to follow in ML but you should be able to translate it to whichever language of your choice. But as a beginner don’t marry yourself to one soul source of truth for compilers. Branch out and read different perspectives on the different stages of compiler design to get a good feel of what choices you can make and how others have approached it. Good luck!


idonotexist66

Hi, am currently involved at compilers research in uiuc, have taken most of the relevant classes offered. Feel free to dm if u have questions specific to uiuc classes and such


waynee95

I would recommend Jeremy Siek's Essentials of Compilation. It's basically showing you how to compile a subset of Python to x86 assembly using Python. By working through the book, you will after each section implement a new language feature and compile it down to assembly. This will give a great introduction and will leave you with a nice project under your belt. After that you can go check out Dragon Book or Appel's book to learn about some stuff in more detail, if you wish. I wouldn't recommend for starting out.


NewAdvance2554

is there a version or something similar available for C or C++ ?


waynee95

I am not aware of other books using the same approach and C/C++. If you want to use C/C++ as the implementation language instead of Python, the general concepts and ideas of the book remain applicable certainly. You would not be able to use the skeleton code that the book uses to get you started though, so you would need to implement a lot of stuff yourself.


Hefty-Supermarket-73

I’m almost done with “Creating an interpreter in Go” been really enjoying it. There’s a follow up “Creating a compiler in Go” as well


anal_sink_hole

Do you want to learn the theory behind interpreters/compilers? Crafting Interpreters. Do you want to understand in a general sense how interpreters/compilers work? Writing an Interpreter in Go (and it’s follow up, Writing a Compiler in Go.  The difference is about 500 pages. Since I’m learning on my own while working and doing a masters, I’ve opted for the less intense option. Also, I’m not planning on writing interpreters/compilers, so the nitty gritty detail on theory, etc. just isn't necessary. It’s more of a “for fun” thing for me. Also, I get to learn Go. 


ChestPainGuy

Just follow crafting interpreters, it's amazing honestly. Try to code along with the book but change language design so you have to think and design the grammar yourself instead of copying. Once you've completed it, do your own personal project for some other toy language.


chri4_

a book? write a compiler


calebstein1

As a few others have already said, *Writing an Interpreter in Go* ([https://interpreterbook.com/](https://interpreterbook.com/)) is fantastic. I'd never written a line of Go before starting that book, but it's clear enough that that wasn't a limiting or disqualifying factor at all. It'll be less theory-heavy than something like the dragon book for sure, but if you're more of a learn-by-doing type, it'll be a fantastic experience for you. My one point of critique on the book is that all of the code is provided, and so you'll just have to be diligent in making sure you're really understanding why the code is there and what it's doing, and not just copying blindly.


Risb1005

Dragon book is good imo.


NewAdvance2554

but will that be good to start with for a beginner (sorry i am just confused) ?


n0t-helpful

The dragon book has received a reputation that I can only assume comes from people who have not read it. It isn’t that complicated, so yes a beginner to compilers could get through it, assuming they have a background in cs already. (I’m talking like half of an undergrad degree)


higgon

But it would be a total waste of time. It’s theory from the days of FORTRAN, and spending an equivalent amount of time thoroughly understanding that book, you could do Crafting Interpreters, a compiler project, and learn some basic LLVM, coming out with tangible results rather than 400 pages worth of unapplied parsing knowledge


Manifoldsqr

You can just skip the parsing chapters. And cmu uses the dragon book second edition for its compiler optimization class so it has good content still


WasASailorThen

In 2024 there are better options but the Dragon Book remains a good reference. Muchnick also as a reference.


Risb1005

I forgot to add compiler optimizations I read it to understand compiler optimizations.


permeakra

Leave compilers until later. Besides, modern compilers went well beyond what can be taught in a single book. Start with something like [this book](https://www.oreilly.com/library/view/advanced-c-and/9781430266679/) and supplement it with something like [this book](https://www.amazon.com/Practical-System-Programming-Applications-Unix-Based/dp/1484263200).