← Back to context

Comment by awesomeMilou

1 day ago

Is there also a self guided course for "basic compilers", before stepping into an advanced level?

I'm a fan of the structure used in Essentials of Compilation [1][2] and Writing a C Compiler [3]. If you want to start with interpreters, I like Essentials of Programming Languages [4]. I have to admit, as popular as Crafting Interpreters is on this site and others, I'm not a fan. Others seem to love it so it's worth a shot, and freely available.

EOC and EOPL are a bit on the academic side, but, I think, they're highly approachable aside from the issues some people have with Scheme and Racket (the Python version of EOC would address that issue). Afterwards, I think the other, deeper and more academic texts on compilers become more approachable.

[1] https://mitpress.mit.edu/9780262047760/essentials-of-compila... - Racket version, has an open access version

[2] https://mitpress.mit.edu/9780262048248/essentials-of-compila... - Python version, has an open access version

[3] https://nostarch.com/writing-c-compiler - Your choice of implementation language

[4] https://mitpress.mit.edu/9780262062794/essentials-of-program... - Scheme, but works in Racket

I'd say check out Crafting Interpreters [1]. It has 2 parts, the first in Java for doing a treewalk Interpreter in Java before going farther with a version written in C.

1. https://craftinginterpreters.com/

  • Not GP, but after doing Crafting Interpreters I was kinda left with a gap in my knowledge regarding the conversion of an AST into native code. Also kinda missing was optimization passes over an AST. I somewhat understand the idea, but it would definitely be nice to have a more guided book/article for this.

    Crafting Interpreters is definitely a recommended read, but it stops at Interpreters (fair enough, the book is thick enough). Crafting Compilers would need at least 4-5 extra chapters IMO.

    • Most of the work involved in emitting code deals with somewhat arbitrary hardware details. Pretty much the only way is to get familiar with your target hardware features, instructions, and platform ABIs. ISA manuals all have sections describing these, they're pretty much always very dry and "linguistically rigorous" so it's not easy to read but everything you need is there. Actually emitting instructions is pretty boring and mechanical outside of some considerations and subtleties with hardware-specific optimization, OS calling conventions, register selection, etc.

  • Hmm I would have hoped for something more formal and that's focused on compiled runtimes, instead of dynamic runtimes

    Still, I appreciate you replying, I'm sure you meant to be helpful!

I suggest starting with the old but classic Compiler Construction for Digital Computers by David Gries. Pair it with some modern books recommended here and you should be good.

David Gries - https://www.cs.cornell.edu/gries/ and https://en.wikipedia.org/wiki/David_Gries

Dutch computer scientist Dick Grune has written of Compiler Construction for Digital Computers that "entire generations of compiler constructors have grown up with it and they have not regretted it."

Note that Dick Grune himself is famous for his books on compilers/programming languages - https://dickgrune.com/index.html and https://en.wikipedia.org/wiki/Dick_Grune