Representing C#3 code as an Abstract Syntax Tree in XML

試著忘記壹切 提交于 2019-12-04 14:35:53

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

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

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.

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 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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!