Sunday, 24 August 2014

AbstractCode - New compiler front-end

Hey guys,

It's been a while, I know, and the reason for that is that I've been working on something rather big and ambitious for a while again.

Today I present you AbstractCode, a compiler front-end framework. This framework allows you to parse source codes written in C# (and VB.NET, however its development is way behind the C# parser), and access it through a so called Abstract Syntax Tree or AST for short. Furthermore, this will allow you to resolve member references specified in the code, such as type or variable references. It will also detect some of the syntax errors as well as some deeper analysis such as ambiguity and unknown identifiers. When the AST is acquired from the input source code, it is possible to add and remove members to the tree or modify them. Last but not least, after applying modifications to the AST, it is possible to write formatted C# and VB code from it again.

Below are some screenshots of the test application I quickly made. The left side is where the input code should be typed in, and the TreeView at the right represents the AST that is being generated from the source.


 When we try to resolve an identifier, such as the "Console" word in the example below, we get an instance of a ResolveResult class that gives us information about the identifier.

 It also works with local variables and members defined in the source itself. Below an example of the resolution of the identifiers x and MyObject in the MyMethod method which are both declared in the source.

This engine can be used for deep analysis of source codes, give suggestions like IntelliSense of Visual Studio, or refactor the code by renaming symbols or improving the source code by adding some modifications. In the end this is going to be integrated within LiteDevelop, in order to have a more powerful code editor.

Let me know what you guys think of it.

Regards