Want to Write a Compiler? Just Read These Two Papers

18 years ago (prog21.dadgum.com)

Alternatively, you can learn macros, as PG might suggest. Fundamentally, compilers just translate one string of symbols into another. The ones we're familiar with just translate a high level language into assembly. But there are others -- every object relational model system has a defacto compiler.

  • If you take a look at that nanopass paper, it's very much in the "just use macros" school of thought. It's even in Scheme.

    For the tldr crowd, http://www.cs.indiana.edu/~dyb/pubs/nano-jfp.pdf.

  • With that approach you won't be able to write a compiler for anything other than a (suboptimal) Lisp derivative, which itself is just a small part of computing world. Take a look at the GNU Compiler Collection and see how far it is to write a working optimizing compiler from the Lisp macro paradigm.

    • I don't claim that this is the only way to learn how to write compilers, it's just one surprisingly effective way.

      And I actually think skill in generalised, simple, macro-type compilers is more useful, generally, than knowing the ins and outs of optimizing compilers, but that's just me.

      For the sake of discussion, what are some of the important things for optimizing compilers that you can't do with this approach? I'm having trouble finding any -- both in a literal sense of possibility, and from a practical standpoint.

      8 replies →

    • And even if writing a more complete compiler wasn't difficult enough, there's more much to it. There are complex details like exception handling (stack unwinding, signals...), graphical debuggers, interface with GUI libraries, threads, etc.

      The fact that only commercial (and expensive) Lisp implementations have all these features is a hint that they're not trivial.

      14 replies →

So did he spell Knuth wrong as a typo or through ignorance? Or is this some subtle insult? Doesn't seem to thing Perl qualifies as useful either...Oh well, one less opinion to worry about.

  • It was a joke, a mistake that a newbie intimidated by huge textbooks might make.