Monday, March 02, 2009

Compiler, Scanner, and Lexer, Oh My!

As with all my pursuits, I generally sit around and think "real hard" for a "long time."  So, for the checklist of things I have begin, I can now add the ultimate compiler.

Being the generalist, yeah basically a "bard," I have always considered it a formidable task to write a compiler.  For the uninitiated, a compiler takes a string of text and converts it into a machine executable program.

For instance, a "C" program like such:
#include

int main() {
printf("Hello, World!\n");
}
Then would be compiled into a program which would print "Hello, World!" onto the screen.  Simple enough - but actually there's a huge amount of work involved.  Thus, my long arduous "thinking about it... yup"® has persisted, until a couple of days ago when I figured what the hell, I'm not getting any younger!

And as always, I figure that if I'm going to put so much effort into parsing a single language such as "C" then by goodness, I'm going to make a compiler that can parse nearly anything.

So I wrote up a new language, hence forth known as "Plato," and have written the scanner for it. I suppose it's a GLR if you want to be exact, but in actuality it's "what works best" based on a ruleset.  After completing about 50% of the scanner I realized there is indeed a better way, so now I'm writing a full-blown compiler tool suite.

The final product will be a universal compiler - taking Java, C#, C++, C, perl, assembler and Plato languages and generating a program which interoperates between any language you can define a human readable ruleset for.  But for now, I'm simply writing Plato.

No comments: