HACKER Q&A
📣 kinga254

Best Resources for Compiler Construction


I would like to learn compiler construction from ground up, create a simple Lang whether compiled or interpreted. Preferably something I can go through sequentially from start to finish


  👤 rramadass Accepted Answer ✓
The best simple introduction i have found to the whole domain of Programming Languages/Interpreters/Compilers construction using tools is "Chapter 8, Program Development" in the book The Unix Programming Environment by Kernighan & Pike. They develop a language and interpreter for "hoc(higher order calculator)". It is just about 40 pages which you can finish in a week and really understand the various pieces involved and how they fit together. I highly recommend not looking at anything else before finishing this.

Once the above is done, you can take a look at any of the popular Compiler construction books/resources many of which would be recommended here. One less well-known but comprehensive work is Project Oberon: The Design of an Operating System and Compiler by Niklaus Wirth.


👤 lebuffon
One of the simplest interpreters that also has a compiler built-in is Forth. It is somewhat heretical to conventional computer science but it can be fully understood top to bottom by normal humans due to it features or lack thereof. :)

A quick search found this repository of JonesForth which is a literate programming version of a Forth system that describes the code as it goes along. There appears to be source for various targets.

https://github.com/phf/forth

It is a very interesting exercise that shows you a kind of bare minimum requirement way to make a language and provides insights for what is missing to build more conventional languages.


👤 daoistChuckle
https://keleshev.com/compiling-to-assembly-from-scratch/ I have been going through this book and it is really good so far.

👤 smlckz

👤 otras
I've heard good things about Writing A Compiler In Go, which is a sequel to Writing An Interpreter In Go. I've worked through some of the latter and have enjoyed it so far.

https://compilerbook.com/


👤 brudgers
Crenshaw’s Let’s Build a Compiler might be an option. https://compilers.iecc.com/crenshaw/

👤 potta_coffee
Principles of Compiler Design is old but still a great book, one of the best CS books I've read and it got me going with compilers. I'm reading an old copy from the 70's.