API比较AST? [英] API to compare AST?

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

问题描述

有一个开源的Java API,允许比较Java源代码code两个抽象语法树?

我想看到这两个语法树之间的差异,类似于它是如何在比较工具完成的。


解决方案

大多数差异工具比较行,没有语法树(见的 Wikipedia文章讨论)。

有是谈谈如何做语法树进行比较,例如一些介绍技术论文,
DIFF / TS:一个细粒度结构变化分析

有用于任何地方,据我所知,可用的计算树的差异没有的API。问题是比第一声音更复杂的,如果你想获得一个最小的差异。但基本技术是使用 Levenstein距离指标

我们已经推出我们自己对我们的 SmartDifferencers 线;幸运的是,我们有很好的前端为众多汉语语言产生精确AST的。

您最终获得额外的惊喜,比如人们希望,尽管事实上,你有什么是AST的比较意见,想比较破碎的文件,以比较语言的方言你的语法不匹配,或codeS包含其他语言等的插入。做用线差异不具有这些问题,这是一个原因线差异是wides $ p $垫和树差异不大。

Is there a open source java api that allows to compare two Abstract Syntax Trees of java source code?

I would like to see the differences between the two syntax trees, similar to how it is done in diff tools.

解决方案

Most diff tools compare lines, not syntax trees (see Wikipedia article for discussion).

There are some techical papers that talk about how to do syntax tree compares, e.g., Diff/TS: A Tool for Fine-Grained Structural Change Analysis

There are no APIs for computing tree differences available anywhere as far as I know. The problem is more complex than it first sounds, if you want to get a minimal diff. But the basic technique is to use some variation of Levenstein distance metrics.

We had to roll our own for our line of SmartDifferencers; fortunately, we have really good front ends for many langauges to produce accurate ASTs.

You end up with additional surprises, such as people that want to compare comments in spite of the fact that what you have are ASTs, wanting to compare broken files, to compare language dialects your grammar doesn't match, or codes that contain insertions of other languages, etc.. Do diff by lines doesn't have these issues, which is one reason line-diff is widespread and tree-diff is not.

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

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