antlrabstract-syntax-treecoboleclipse-jdt

Convert COBOL AST to Java Source file


My Requirement is to convert COBOL to JAVA , to achieve that I was planning to convert to AST and then to Java. I was able to get the AST(Abstract Syntax Tree) of COBOL. Now I am l looking for Java source code generation from AST.

I was hoping I could generate CompilationUnit or AST (JDT) from a XML file , but unfortunately all the available APIS(Eclipse JDT) are creating AST from Java source. I would infact wanted to use XML file as input.

Does any one know how to create ASTNode from its XML counter part?


Solution

  • If you have a COBOL AST, you can't "just generate" Java source code from it. COBOL constructs are not Java constructs.

    Something has translate the COBOL constructs to sensible Java equivalents. You're surely not going to read an XML file representing the COBOL AST directly into a a Java AST; this implies doing the translation as you read the XML. The translation is more difficult than you can reasonably do that way.

    What you really want to do is to translate a COBOL AST to a Java AST. If that were your plan, you could read the XML and build a COBOL AST, then build COBOL AST -> Java AST translation rules and run them.

    Once you have a Java AST, you can generate Java source code from it using various kinds of tools. I think Eclipse JDT will do that. If not, you can build your own.