While I have been backpacking through Europe my urge to code has not been completely ignored. On trains and planes and buses I have been working my way through “The Dragon Book” and “The Definitive ANTLR Reference”.
As of a few minutes ago I am probably too proud of the fact that the command line:
cflat.exe SimpleTest.cflat -o SimpleTest.dll
Compiles this:
public class SimpleTest
{
public int GetValue()
{
return 1;
}
public int Main()
{
int a = 2;
if(true){
return a + GetValue();
}
return a;
}
}
into this:
There is lots more to do but I finally feel like after much experimentation I am on track to having my own compiler for a very small subset of C#.
I built a compiler once before for possibly my favorite university class: Programming Language Implementation. I became interested in compilers again after playing around with the first Oslo release and the combination of M/IntelliPad.
Of course this compiler will never be of any use except as a learning tool for me. Currently I am using ANTLR for parsing/lexing and Reflection.Emit to target the CLR. Once I am happy with the feature set of my C# subset I am planning to look into other options for parsing including MGrammar and F#. Before that I am going to need to add at least one looping construct :-).
All the source and test are available in my github repository in case anybody wants to follow along.