[antlr-interest] Can ANTLR transform AST to XML?
John D. Mitchell
johnm-antlr at non.net
Sun Mar 13 10:44:40 PST 2005
>>>>> "FC" == FC <tangfc2001 at yahoo.com> writes:
[...]
> In my project, I want to use Antlr to parse my Java source code to
> generate AST tree. But I want to store AST in XML so that I can use this
> XML in my next module of the project. I wonder if the current Antlr can
> provide to tranform AST to XML.
Sure, just write a tree walker which dumps out the AST into an XML format.
The classic way is to use a syntax-directed approach where you just embed
e.g., print statements as the actions of the tree walker.
If you have more complex ordering/reuse/etc. needs in your output, you
might want to take the approach of using the walker to instantiate
StringTemplates. Ter wrote an article about this:
http://www.codegeneration.net/tiki-read_article.php?articleId=77
Have fun,
John
More information about the antlr-interest
mailing list