← Back to context

Comment by userbinator

7 years ago

This looks like something similar to Crenshaw's excellent tutorial of the same name:

https://compilers.iecc.com/crenshaw/

and its x86 port: https://github.com/lotabout/Let-s-build-a-compiler

As interesting as Lisp-family languages are, I still think it's better to use something with more traditional syntax and start with parsing, because that both reaches a much wider audience and gives a very early introduction to thinking recursively --- the latter being particularly important for understanding of the process in general. A simple expression evaluator, that you can later turn into a JIT and then a compiler, is always a good first exercise.

> a very early introduction to thinking recursively

Not everything needs to be on a so-you-have-never-programmed-before level. This series explicitly assumes "some knowledge of native-code build processes, Lisp, C, and x86 assembly language". People who know Lisp should have had an introduction to thinking recursively already.

Parsing would be a useless distraction for someone interested in writing a Scheme compiler in Scheme.

I think I partially agree, but that it mainly depends on the audience. I've found that parsing and recursion appear in more areas than just compilers, to the point where it'd be relatively difficult to avoid them. Machine code generation and the underlying implementation of high-level primitives (closures, tail-call recursion, and the like) hasn't, at least in my experience, been "naturally-occurring" to the same extent.

In terms of creating a "learn compilers from scratch" resource, Crenshaw's approach is definitely better. The trade-off would be that it'd take longer to get past the "writing a recursive descent/LR parser" phase, and it might never get to higher-level language features at all depending on the input language you go with.

  • I've worked my way through quite a few tutorials on implementing Scheme I think you're absolutely correct that detailed material on implementing high level features, especially in machine code, is lacking. I'm very grateful for this tutorial. Can't wait for the next part!