8

I want to create an XML file with AST representation of source code, but without compiling it. I didn't find any sufficient solution so far. Here is what I tried:

  • Using XML printer in clang - clang -cc1 -ast-print-xml - it would be nice, but it was removed from clang
  • srcML toolkit, which in theory works well, but has poor parser (for Java it's not even fully 1.5-compatible)

Are there any other alternatives?

2
  • Clang won't handle Java, AFAIK. Commented Sep 1, 2014 at 12:51
  • FWIW, the "XML" that was printed by Clang, wasn't really XML. Commented Jan 30, 2016 at 4:06

1 Answer 1

3

For Java, see What would an AST (abstract syntax tree) for an object-oriented programming language look like?

For C, see get human readable AST from c++ code

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

I don't think XML is really a good idea: it is enormous and klunky, and the analysis tools you can bring to bear on it are ... what? XSLT: That's not very useful for analyzing programs. Read the XML into a DOM and climb over that? You'll find that you are missing lots of useful support (symbol tables, etc.); AST's are just not enough. See my essay on Life After Parsing (check my bio or google).

You are better off using a set of integrated machinery that provides all kinds of consistent support for analyzing (multiple) programming languages (using the ASTs as a foundation). This is what DMS is designed to do.

Sign up to request clarification or add additional context in comments.

2 Comments

Heh, I felt that you will write an answer. I saw your answers in related questions already. Anyway, thanks :)
You asked if there were any alternatives. I'd be happy for other people to point out DMS, but they don't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.