10 ms·
Build a Compiler in Five Projects
- AdityaSanthosh 11mo agoHi, seems like an interesting course. I haven't studied compilers in my undergrad( I'm an electronics student) but I have been working as a programmer who studied c and bit of low level languages. Is there any prerequisite compiler knowledge required for this course?
- ktimespi 11mo agoThe only prerequisite here is probably Racket, to follow along with the book
- UncleOxidant 11mo agoThe Essentials of Compilation book mentioned is only ~$24 on Amazon. Usually books like this are much more expensive. I ordered a copy.
- almostgotcaught 11mo agolooks like a fun book but just be forewarned real compiler engineering is nothing like what's covered there.
- anta40 11mo agoAny recommendation for a more realistic book? I think hacking GCC/LLVM can be pretty challenging, but hey they are real, production-grade compilers and not just typical academic projects.
- almostgotcaught 11mo agothere are no good modern compiler books - everything that's been written down pales in comparison to what GCC/LLVM really involve. recently i found Engineering a Compiler by Cooper and Torczon when reviewing/prepping for interviews - it wasn't bad. also there's now LLVM Code Generation by Quentin Colombet but that's basically a code walk-through of LLVM (it doesn't cover any of the algos). and it was probably out of the date the second it got published lol (not really but maybe). the truth is that trying to learn how to build a compiler from a single book is like trying to learn how to build a skyscraper from a single book.
- kmicinski 11mo agoRespectfully, I think what you mean is that there are no books which give you the experience of hacking on LLVM for several years.
- yu3zhou4 11mo agoIs Dragon book still relevant? Do you recommend any other learning resources other than reading the source and contributing to llvm?
- anta40 11mo agoI heard that new volume is updated with newer stuffs like data flow analysis, garbage collection, etc. Anyway the book doesn't teach you how to build a basic working compiler, so need to consult another materials. Try Andrew Appel's "Modern Compiler implementation in Java/C/ML" or Writing a C Compiler (https://norasandler.com/book https://norasandler.com/book) which is much more recent. Eventually, you'd want to hack GCC/LLVM because they are production-grade compilers.
- f1shy 11mo agoIMHO absolutely. The basics of lexer and parser are still there. Some of the optimizations are also relevant. You just cannot expect to read the book and be able to write GCC or LLVM from scratch(1). For learning deeper about other advanced topics there is: https://www.cs.cornell.edu/courses/cs6120/2025fa/ https://www.cs.cornell.edu/courses/cs6120/2025fa/ and https://mcyoung.xyz/2025/10/21/ssa-1/ https://mcyoung.xyz/2025/10/21/ssa-1/ So maybe writing a compiler with exactly one FE (for a simple language) and one BE (for a simple architecture), with say 80% of the optimizations could be a doable project. (1) We should define what we mean by that, because there are thousands of front-ends and back-ends.
- kronnpp 11mo agoI taught in the past and still like the trilogy of books > Modern Compiler Implementation by Andrew W. Appel It comes in three flavors C, ML (Meta Language), and Java https://www.cs.princeton.edu/~appel/modern/ https://www.cs.princeton.edu/~appel/modern/ Writing a compiler in Standard ML is as natural as writing a grammar and denotational semantics. Compiler writing is becoming an extinct art.
- fragmede 11mo agoReal compiler engineering covers a lot of ground. This book is an intro to it, not the whole everything. No need to posture about it.
- kryptiskt 11mo agoI'm knee deep in clang at the moment and I'm so fed up with real compiler engineering. Give me Chez Scheme and the nanopass compiler any day. That is so much better than the big ball of mud that goes into a "real" compiler.
- almostgotcaught 11mo ago..... Yes that's exactly my point that these cutesy books give a completely inaccurate picture of what the job is really like.
- pjmlp 11mo agoMost people just want to compile their toy language into machine code and be done with it.
- declank 11mo agoThere is also the Python version too and available free. I do like the register allocation/graph colouring chapter.
- evnix 11mo agoMost of these compiler projects and books would be 100x more popular and accessible if they were in Javascript
- wiseowise 11mo agoJust use LLM to translate example to whatever language you want.
- derrida 11mo agoNow now, isn't that what a compiler does?
- Iwan-Zotow 11mo agoSICP in JAVASCRIPT exist somewhere
- fjfaase 11mo agoIt surprises that they are still teaching parsing techniques that are based on limitation from 40 years ago, when memory was limited and you had to parse a file one character at the time. Why not start with a back-tracking recursive descent parser on a file stored in memory? Can be made efficient with some simple caching. In an introduction course there is no need to aim for maximum performance if parsing a 10k lines program takes less than a second.
- vintagedave 11mo agoAre you referring to lookahead, as in allowing more ambiguous grammars?
- fjfaase 11mo agoNo, even if a grammar is ambigious it can require unbound look-ahead to be parsed, although this is very rare the case for meaningfull grammars such as the ones you would write for a programming language. What I wanted to say that you do not need complex algorithms to implement parser if you do not have a grammar that can be parsed with look-ahead lexical element.
- fjfaase 11mo agoI mend to say: No, even if a grammar is not ambiguous ...
- fjfaase 11mo agoSorry, I mend to say: Even if a grammar is not ambiguous, it can require unbound look-ahead to be parsed correctly [1]. The grammar of C is ambiguous. The statement "a * b;" can be both parsed as a variable declaration of the variable 'b' of type pointer to 'a' and as an expression consisting of a multiplication of 'a' and 'b'. It all depends on whether 'a' is a type or not. In most cases it would be a type definition, because why multiply two variables and ignore the result. One trick to deal with this is to give precedence for the type declaration grammar rule over the expression grammar rule. However, this is not something that can be done with many parser generating tools. Yet the first C compiler where single pass compilers with a single look-ahead lexical token probably implemented as a recursive descent parser. It worked, because it kept a (reverse) list of all variable declarations, which allowed it to determine when 'a' was parsed if it was the start of some declaration or the start of a statement based on whether it was defined before as a type or not. [1] https://stackoverflow.com/questions/12971191/grammars-that-require-unlimited-lookahead https://stackoverflow.com/questions/12971191/grammars-that-r...