Can I get XML AST XML C / C ++ / Java code without compiling it?

I want to create an XML file with AST code for the source code, but without compilation . So far, I have not found a sufficient solution. Here is what I tried:

  • Using an XML printer in clang - clang -cc1 -ast-print-xml - would be nice, but it was removed from clang
  • srcML toolkit, which theoretically works well, but has a bad parser (for Java it is not even fully compatible with 1.5)

Are there any other alternatives?

+6
source share
1 answer

For Java, see What will the AST (Abstract Syntax Tree) look like for an object-oriented programming language?

For C, see getting humanoid AST from C ++ code

Both of them are made by one engine: our DMS Software Reengineering Toolkit. DMS also has a complete C ++ 11 parser that can create similar XML. (EDIT Jan 2016: now full C ++ 14 for GCC and Visual C ++).

I don’t think XML is a really good idea: it is huge and klunky, and the analysis tools you can bring to it are ... what? XSLT: This is not very useful for program analysis. Read the XML in the DOM and get over it? You will find that you lack useful support (character tables, etc.); AST is simply not enough. See My essay on life after parsing (check out my bio or google).

You are better off using a set of integrated mechanisms that provides all kinds of consistent support for the analysis of (multiple) programming languages ​​(using AST as the basis). This is what DMS is designed to do.

+3
source

Source: https://habr.com/ru/post/974356/


All Articles