将 C#3 代码表示为 XML 中的抽象语法树 [英] Representing C#3 code as an Abstract Syntax Tree in XML

查看:40
本文介绍了将 C#3 代码表示为 XML 中的抽象语法树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 C#3 是否有类似于 GCC_XML 的东西;基本上是一种用 XML 表示程序的整个句法结构的方法.

I was wondering if there is something similar to GCC_XML for C#3; basically a way to represent a program's entire syntactic structure in XML.

一旦创建了表示,我希望将其解析为 XDocument 并从那里解释或查询它.

Once the representation is created, I was hoping to parse it into an XDocument and interpret or query it from there.

有没有工具可以做到这一点?

Are there tools out there for this?

推荐答案

我们的 DMS 软件Reengineering Toolkit 可以用 C# 2/3/4 做到这一点.(编辑 2014:现在是 C#5,编辑 2020:现在 C#7 正在使用 C#8)

Our DMS Software Reengineering Toolkit can do this with C# 2/3/4. (EDIT 2014: and now C#5, EDIT 2020: now C#7 working on C#8)

DMS 具有用于 C#(以及 Java 和许多其他语言)的编译器准确解析器.

DMS has compiler accurate parsers for C# (as well as Java and many other languages).

它会自动为它解析的任何内容构建完整的抽象语法树.每个 AST 节点都标有文件/行/列,用于表示该节点开始的标记,最后一列可以通过 DMS API 调用计算.它将注释附加到树节点,因此它们不会丢失.DMS 还可以从 AST 或修改后的 AST 重新生成有效代码;这使它能够用于代码修改或生成.

It automatically builds full Abstract Syntax Trees for whatever it parses. Each AST node is stamped with file/line/column for the token that represents that start of that node, and the final column can be computed by a DMS API call. It attaches comments to tree nodes so they aren't lost. DMS can also regenerate valid code from the AST, or from a modified AST; this enables it to be used for code modification or generation.

它有一个从 AST 生成 XML 的内置选项,包括节点类型、源位置(如上)和任何相关的文字值.命令行调用是:

It has a built-in option to generate XML from the ASTs, complete with node type, source position (as above), and any associated literal value. The command line call is:

 run DMSDomainParser ++XML  <path_to_your_file>

DMS 本身提供了大量的基础设施来操作它构建的 AST:遍历、模式匹配(针对基本上以源代码形式编码的模式)、源到源转换.

DMS itself provides a vast amount of infrastructure for manipulating the ASTs it builds: traversing, pattern matching (against patterns coded essentially in source form), source-to-source transforms.

它具有控制流、数据流、指向分析、C、COBOL和Java的全局调用图;这就是 C# 的全部内容.

It has control flow, data flow, points-to analysis, global call graphs for C, COBOL and Java; that's all coming for C#.

DMS 旨在成为一种比 XML 更好的处理此类代码的解决方案.

DMS was designed to be a much better solution than XML for manipulating such code.

这篇关于将 C#3 代码表示为 XML 中的抽象语法树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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