2011-03-01 82 views
0

我想通过所有可用的Java(或任何其他语言)的源代码在一个给定的项目:工具来分析代码的语法

  1. 设置关键字的置换及其关系
  2. 的统计分布
  3. 挑出重复序列字符,构造(模式)。

你会推荐我什么样的工具集?

例如:

我希望它能够挑选:

* (*) { 
    * 
} 

出了的

public static void main (String[] args) { 
    System.err.println("Specific Text"); 
} 

\n; 
System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
    System.err.println("Specific Text"); 
+0

ctrl + F在您的IDE与正则表达式? – 2011-03-01 16:01:24

回答

3

您需要一个语言解析器。我能想到的一个是http://www.antlr.org/。您最终将使用Java已存在的语法并解析文件并查找令牌。例如,如果,等,等...都是解析器会告诉你的所有关键字。但123不是关键字。

+0

BTW,Terence Parr(ANTLR作者)撰写了这本书:http://pragprog.com/titles/tpdsl/language-implementation-patterns,它很容易解释如何做一个你需要的语言应用程序。如果你对令牌处理器,解析器,ast等等一无所知,我建议你阅读这个boook。 – OscarRyz 2011-03-01 16:03:42