4 ms·
That’s very well put. I’ve actually really wanted a “cookbook” for compilers. Basically small, self contained lessons for writing a particular part of a compile
by _hardwaregeek 8y ago
That’s very well put. I’ve actually really wanted a “cookbook” for compilers. Basically small, self contained lessons for writing a particular part of a compiler. I.e. here’s how to write a typechecker, or how to write a garbage collector. The closest to that I’ve found is Crafting Interpreters. A lot of the compilers textbooks focus on the theory or general concepts, which is great, but I want to get my hands dirty. I’m not reading the book to learn the theory of compilers; I’m reading to book to write a compiler.
- mamcx 8y agoI agree for the cookbook. I'm building a lang I have scavenged so much info from so many places, but all is kind of disconnected. Or worse, all stop at generate the AST, and barely interpret the AST at the level of a calculator and maybe simple functions. For example, I need like 5 different sources to finally have a grasp in how pattern match, and build a solution that later found in another paper.
- mepian 8y agoThere is a great paper by Abdulaziz Ghuloum, An Incremental Approach to Compiler Construction, that is pretty much the cookbook you want: http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf "We show that building a compiler can be as easy as building an interpreter. The compiler we construct accepts a large subset of the Scheme programming language and produces assembly code for the Intel x86 architecture, the dominant architecture of personal computing. The development of the compiler is broken into many small incremental steps. Every step yields a fully working compiler for a progressively expanding subset of Scheme. Every compiler step produces real assembly code that can be assembled then executed directly by the hardware." There is also a work-in-progress effort to write a more extensive textbook that follows the same approach to teaching compiler development, using Racket instead of R5RS Scheme: https://github.com/IUCompilerCourse/Essentials-of-Compilation https://github.com/IUCompilerCourse/Essentials-of-Compilatio...
- _hardwaregeek 8y agoI was recommended that paper by someone else. Just need to get around to reading it :) The main roadblock I'm having right now is typechecking. I've implemented Hindley Milner in Haskell and played around with Turnstile, but I still don't know enough theory to invent my own type rules for an imperative language. Something like "Type Theory for the Working Programmer" would be excellent. I just got a copy of TaPL, so maybe I'll just use that.