Java/抽象语法树转化为 XML 表示 [英] Java / Abstract Syntax Tree into XML representation

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

问题描述

您是否知道有任何工具可以从 Java 程序或类创建 AST 并从 AST 创建 XML 表示(集合或单个 XML 文档)?

do you know of any tool which creates an AST from a Java program or class and creates an XML representation (Collection or single XML document) from the AST?

亲切的问候,
约翰内斯

kind regards,
Johannes

推荐答案

我们的 DMS 软件Reengineering Toolkit 及其 Java 前端 可以直接执行此操作.您要求 DMS 解析文件,并使用命令行开关 ++XML 生成 XML 转储.

Our DMS Software Reengineering Toolkit with its Java Front End can do this directly. You ask DMS to parse the file, and produce an XML dump using a command line switch ++XML.

请参阅面向对象编程语言的 AST(抽象语法树)会是什么样子?.

作为一般规则,我们不建议这样做,原因如下:

As a general rule, we don't recommend this, for several reasons:

  • 真实文件的 XML 输出非常庞大,需要花费大量时间来编写和读取

  • XML output for real files is really enormous, and takes a lot of time to write and read

大多数人这样做是因为他们相信通过 XML 表示,只需一点点 XSLT 就能得到他们想要的

Most people do this because they believe with an XML representation that just a little bit of XSLT will get them what they want

如果您打算修改代码,一旦您拥有 XML,您几乎无法重新生成它.

If you intend to modify the code, once you have the XML you pretty much can't regenerate it.

DMS 提供的机制(属性语法、符号表、流分析、模式匹配和源到源转换、来自 AST 的源再生,正是您真正想要的,您可以通过在解析步骤之后使用 DMS 而无需导出 XML

The machinery that DMS provides (attribute grammars, symbol tables, flow analyses, pattern matching and source-to-source transformations, source regeneration from the AST, is what you really want, and you get access to it by using DMS after the parsing step without exporting the XML ever

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

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