The Word with Rev. C. Bennett hoffman

7Mar/081

The LolSharp Compiler part 1

Last Things First

In this part, we're going to build a very simple compiler to turn a subset of the LolCode language into a .NET executable. I've decided to take a depth first approach, as opposed to a breadth first approach, let me explain. I could starting by writing the whole parser and then building each part of the back-end one at a time. While that's certainly one way of doing it, I'm not that patient. In order to have something shiny to play with faster, the approach will be to build a working-but-limited program from end-to-end. Then, in subsequent parts, we'll add new features and look at what that means for each part of the compiler.

3Mar/080

The Language that Launched a Thousand Ships

Like a lot of people in the world of computer science, games were my gateway drug. Sure these ubiquitous murder-and-sex simulators have turned an entire generation into raving sociopaths, but the real danger of gaming only becomes apparent when you realize that "hey, I could actually make one of those!" Soon our poor, unfortunate youngster embarks on the task of learning to program. His mind becomes addled with logic, mathematics, abstract reasoning, critical thinking, and other such things; unsuitable for the modern age.

After the warm glow of making (or more appropriately, starting) my own games wore off, I found myself gripped by an even more sinister force: computer language design. The progression is completely logical. Why just make games when you can make the thing that is then, itself, used to make games... Anyway, I've wanted to write a compiler for a long time. Now, I've found the language to write it for. May I present LOLCODE:


BTW This line is a comment. Here's the standard "hello world" example.
HAI
I CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE

Ok. Just wait. It's not that crazy. Let me explain. I'm actually going to be working with two languages. Then, all kinds of cool things are possible, like translating from LOLCODE to something more... reasonable. Anyway, the syntax for LOLCODE presents some interesting challenges to work through from a language processing standpoint and the spec isn't what you'd call finished, so there's a large degree of freedom. Technology-wise, I plan to use ANTLR targeted to C# for the LP stuff. Why C#? I'm a corporate whore. Also, I wasn't able to find a quick start tutorial for getting ANTLR up and running in a .NET environment, just bits and pieces. Hopefully I can help someone out who's trying to do the same thing.

Tutorial
part 1
part 2 (coming eventually)