C source code AST parser in Java [closed]

蹲街弑〆低调 提交于 2019-12-13 12:21:52

问题


I'm looking for an C source code parser that can create a comprehensive AST from it.

Preferably a Java library (I'd rather not have to use Python here -> http://code.google.com/p/pycparser/)


回答1:


It may well be easiest for you to use ANTLR and get it to generate an AST based on an existing ANTLR grammar, e.g. the source.

ANTLR has a Java API here: http://www.antlr.org/api/Java/index.html




回答2:


The Eclipse CDT project has a C parser written in Java, see my answer to a similar question.




回答3:


Our C Front End is not in Java, definitely not in Python :-} but provides robust parsers for many real dialects of C code. It goes beyond building just ASTs; it provides a preprocessor, symbol tables, local and global flow analyses, which you will need if you want to do anything to C other than just "having an AST".

It comes built on top of our DMS Software Reengineering Toolkit, which provides the infrastructure for parsing and flow analysis, can apply transforms to the AST using patterns, and can regenerate valid source code.

EDIT July 2015 (in response to comment): DMS itself is implemented in a parallel programming language, PARLANSE, which is C-like in capability but includes fine-grain parallelism constructs as well as exception handling. DMS provides a set of DSLs for defining language processing: a fully-Unicode capable lexer, BNF for grammars, attribute grammars for computing tree-shaped analyses, and source-to-source transformations useful for pattern recognition and rewriting the source code.



来源:https://stackoverflow.com/questions/9315205/c-source-code-ast-parser-in-java

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