Ferry Mulyono

See also: Other Geeks@INDC

C to MSIL Compiler

This was my project for course "Technique of Parsing and Translation" previous semester. It turns out that my group was the only group that was successfully utilizing .NET Platform, right from the lexer down to its code gen. Next tuesday my group will be invited as guest lecturer in the same course for my juniors. I've attached the executables if any of you are interested in low-level IL stuff; this could be a good start =)
Share this post: | | | |

Comments

zeddy said:

I don't think you should call this a C-to-MSIL compiler, since it can't compile this:

#include <stdio.h>

void main()

{

 printf("hello, world\n");

}

You should give a name for your Subset-of-C language instead :)

# May 4, 2007 11:16 AM

zeddy said:

I find your Scanner code to remove whitespace a bit "unelegant". Try refactoring maybe? :)

private void b()

{

   int num;

   while ((num = this.d.ReadByte()) != -1)

   {

       char ch = Convert.ToChar(num);

       switch (ch)

       {

           case ' ':

           case '\t':

           case '\r':

           case '\n':

           {

               switch (ch)

               {

                   case ' ':

                   case '\t':

                       this.b++;

                       break;

                   case '\r':

                       this.a++;

                       this.b = 1;

                       break;

               }

               //** CONTINUE inside SWITCH?

               continue;

           }

       }

       this.d.Seek((long) (-1), SeekOrigin.Current);

       return;

   }

}

# May 4, 2007 11:44 AM

ferry said:

Oops, forgot to mention it. It's not actually C, but subset of C =) Due to the time constraint, we do lots of modification in the grammar to remove ambiguity.

And btw, about the lexer, I know it's not a master piece, haha we did the lexer in 1 day + few hours before presentation. =)

My friend did the lexer using RegEx and I think it's quite powerful and easy to modify. But I haven't got any time to modify anything

# May 4, 2007 12:04 PM