C# CodeDom Parser and C# -> Flash ActionScript

Robin Duebril has a very exciting project in the works (thanks to Brian LeRoux for the link). Robin is using ANTLR to create a C# lexer/parser that loads its results into classes modelled very closely off of CodeDom. The parser still has a bit of work to go, but looks like we may finally have an ICodeParser implementation for C#.

Even more exciting news is that Robin plans on supporting swf/actionscript output from his compiler so that you can write C# code and embed it in your Flash files. As the possibility of C#->SWF is something that I have previously posted about, this is something that is extremely interesting to me (especially since I was also looking at using ANTLR to do the exact same thing).

Robin says his C# parser is going to be available for free use, so, I took a few hours tonight to explore his code and create my own C#->SWF parser as an experiment. It looks like 90% of the C#->SWF process is going to be pretty simple. Across all modern languages, stack based operations and the basic concepts stay pretty much the same. When working with C# for example, you might have the following code:

int i = 1+5;

In ActionScript, this would look like:

var i = 1+5;

Not too different. Now, when we convert this to actionscript bytecode, we get something like this:

Push Integer, 5;
Push Integer, 1;
Add

So, after a few hours getting familiar with his parser and hacking some fixes I now have a pretty basic C# compiler built on top of SWFSource.NET. Lots of missing stuff of course, since this is just an experiment, but it can already handle method definitions most operators (the ones that are 1:1 between ActionScript and C#), function calls, etc. Pretty cool stuff. This could be yet another reason not to buy Flex ;-).

1 Comment

Comments have been disabled for this content.