Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate C# code into AST?

Is it currently possible to translate C# code into an Abstract Syntax Tree?

Edit: some clarification; I don't necessarily expect the compiler to generate the AST for me - a parser would be fine, although I'd like to use something "official." Lambda expressions are unfortunately not going to be sufficient given they don't allow me to use statement bodies, which is what I'm looking for.

like image 809
Erik Forbes Avatar asked Oct 17 '08 19:10

Erik Forbes


People also ask

What is CC translation?

abbreviation for carbon copy : written at the end of a business letter or in an email before the names of the people who will receive a copy.

Is there a better translator than Google?

DeepL Translate: The world's most accurate translator.

What is your name in Arabic Google Translate?

what is your name? ما هو اسمك؟


1 Answers

The Roslyn project is in Visual Studio 2010 and gives you programmatic access to the Syntax Tree, among other things.

SyntaxTree tree = SyntaxTree.ParseCompilationUnit(
    @" C# code here ");
var root = (CompilationUnitSyntax)tree.Root;
like image 192
Paul Rubel Avatar answered Oct 04 '22 05:10

Paul Rubel