6
votes
Looking for a simple language to build a compiler for
I've recently built a brainfuck just-in-time compiler and I'm looking for my next project. I think compiling a more complicated (and more easily written) language would build on what I've learned so far. Rather than design my own language from the ground up, I'd prefer to work with a toy language that already has existing programs and a spec. This would both save me some work and give me more solid ground to build upon.
Scheme! It's a classic, and writing a scheme interpreter is part of SICP.
And it's practical (sort of). Reddit use to run from a lisp, after all!
That does make the parser quite simple!
Bob Nystrom's Lox is a good candidate.
https://craftinginterpreters.com/
Give Lua a shot. Its source code is tiny, in C, extremely embeddable etc. It should be a good match for your requirements.
When I was in school, we built a Pascal compiler. It was pretty straightforward and taught us all the parts of writing a simple compiler from lexing to semantic processing.
Turing is an interesting one that I've tried (and failed) to reimplement successfully. The documentation I linked is for the OOP version of Turing, but there's a simpler spec without classes out there too.
I'm curious, how are you going about writing your parser and are you targeting LLVM or doing it more traditionally?