Tiny Roslyn Compiler Application

Some of the C# 6.0 features are simply amazing. We can try them out as well as Roslyn is available as nuget package for VS 2012(Check in your Extension Manager Tools Options of VS 2012). The Roslyn documentation is available in Codeplex.

Some of the features that are already done in C# 6 include Exception filters, getter only auto properties, and also Await, yes await in try catch finally. In this post I have written a tiny compiler that parses a C# file and dumps the syntax tree on to your console with a code review. So All I have written is

i) Parse and walk the Roslyn compiler syntax tree and dump it.
ii) Written a small Compiler
iii) Use the same to explore if the features that are implemented work fine.

The pre-requisites includes, installing the beta version of roslyn.

i) Create a new Console Application VS 2012, fireup Nuget Console and install Roslyn using the following command

Install –Package Microsoft.CodeAnalysis –Pre

ii) This console application is the tiny compiler that I have written.
iii) Now to dump the syntax tree, I have also written a syntaxhelper class that is going to parse our code file and dumps the syntax as well as compile and figure out errors.
iv) The dump and compile methods are not available as part of syntax tree in Roslyn bets, I have written them as extension methods .
v) Any file that fairly contains a C# Code to be passed as argument. Rename the file as .csfile extension .

I have attached them for your reference. Please feel free to modify the code for better code analysis. Download attachment

About Author – Author is a Technical Architect in Congruent, a Microsoft Gold Certified Partner specializing in Software Application Development.


Tags: Roslyn Compiler, VS 2012
previous post: Hadoop next post: Microsoft announces Developer Preview for Dynamics GP 2015