3

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?

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
Satheesh Cheveri
  • 3,621
  • 3
  • 27
  • 46

2 Answers2

2

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.

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
1

Yes, this is a major task which involves building a semantic model of the COBOL code, and then translating forward from that to Java. A big mismatch is that COBOL is not OO, you have to decide on what are the appropriate classes based on the DATA DIVISION and other data parts. Another big mismatch is the use of PERFORM (basically GOTO with a return - which is however not guaranteed to return). Likewise, for the lack of block structure in COBOL.

Overall, this is a major project which companies such as IBM have spent $millions on.

Kevin Lano
  • 81
  • 2