翻译的C#代码到AST? [英] Translate C# code into AST?

查看:482
本文介绍了翻译的C#代码到AST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是目前可能的C#代码转换成抽象语法树



编辑:澄清;我并不指望编译器生成我AST - 官方一个解析器就可以了,但我想使用的东西Lambda表达式是不幸的是不会是足够给他们不允许我用的语句机构,这正是我要找的。

解决方案

项目是在Visual Studio 2010,并为您的的Syntax树,等等。

  SyntaxTree树= SyntaxTree.ParseCompilationUnit(
@C#代码在这里);
VAR根=(CompilationUnitSyntax)tree.Root;


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.

解决方案

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;

这篇关于翻译的C#代码到AST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆