aravindkanna
aravindkanna

Reputation: 683

generate source code from AST

I understand that any source code can be converted to an AST. Now I want to convert that AST back to source code, but language independent. Is there any tool that helps me out?
By language independent I specifically mean for python and java.

Upvotes: 3

Views: 2169

Answers (2)

somename
somename

Reputation: 19

you cannot convert an AST back to source code according to my opinion. Because the ast generated may be of any language and you cannot convert that ast back to any language you want.

Upvotes: 0

Mike Lischke
Mike Lischke

Reputation: 53522

What you have in mind is a source code translator and it involves a lot more than just generation of some code from the parse tree (ANTLR4 doesn't create an AST btw.). Usually such a translator converts the parse tree into an intermediate representation which abstracts the various language constructs and then uses that to generate code in the target language (with a lot of special handling for everything from the source language not available in the target language, optimization etc.).

Upvotes: 1

Related Questions