JAVA2COB: Rule based translation from java to COBOL


Tool Description

JAVA2COB is a open-source tool that performs the rule based translation of Java code to COBOL.

JAVA2COB Github Repository

Installation

Requirements

  • Java Version 14.0+ (Installation of java is mandatory to run the tool)
  • Gnu COBOL This is needed to run the cobol code generated. The tutorial for installation can be found here 👉 Tutorial

Usage

The tool has a GUI and this can be accessed by following the steps below:

  1. Clone the GitHub repository by running the following command:
    git clone https://github.com/SrikrishnaKidambi/Java-to-COBOL.git
  2. Go to the repo directory cd Java-to-COBOL

  3. Set up the parse tree generation:
    • Change the directory to Antlr: cd Antlr

    • Compile the java files needed to generate parse tree:

      1. For Windows: javac -cp ".;antlr-4.13.2-complete.jar;javaparser-core-3.25.8.jar" *.java

      2. For Linux/Mac: javac -cp ".:antlr-4.13.2-complete.jar:javaparser-core-3.25.8.jar" *.java

  4. Head back to the main tool directory cd ..

  5. Compile the ToolGUI class javac ToolGUI.java

  6. Now we are gdod to go you should be able to see the GUI whenever you run the command java ToolGUI in the tool's base directory.

GUI Usage screenshots


  • screenshot

    • Using the upload button you can upload the java code which needs to be translated in the left part of GUI.
    • You can also directly paste the code copied from any source in the left part without using upload button.


  • elegant icons
    • Click the run button in the left part of GUI to start translation.
    • Select your Operating system in the dialog box as the command to run Antlr differ in both(as seen above) and then you can see the COBOL code in the right part as below 👇.



  • elegant icons


  • elegant icons
    • You can copy the code onto the clipboard by clicking the copy button in the right side of GUI.
    • You can also save the code by clicking the save button in the right side of GUI.


Approach diagram

approach

Key phases in the tool:

    1) Initial set up for the tool:

    The antlr tool will take in the Java 14 grammar as input and provides the java parser and java lexer. We got the java parser and lexer from antlr repo and antlr4 jar from their website. These were the prerequisites for the generation of Parse Tree.

    2) Workflow of the tool:

    When the java source code is given to the tool firstly it is tokenized by the lexer which is called as lexical analysis which converts the code into tokens and those tokens are given to the java parser and it creates the parse tree. An instance of parse tree walker can be created and we can pass the parse tree and custom listener to it to walk the nodes of the parse tree and convert the java constructs into cobol constructs thereby we get the translated cobol code.

    3) Workflow of the code translation:

    We have analysed the data division and procedure division of the code seperately. So one parse tree walker walks through the nodes and returns the identification and data division of the cobol code and the other parse tree walker walks through the nodes and returns procedure division of the code.

    4) Contructs our tool supports:

    We have currently implemented rule based mapping for arithmetic expressions (including int, float, double, long, char, String etc.,), arrays, conditional statements (if-else if-else blocks, switch case), loops, methods.

Goal

JAVA2COB is a tool that is developed to do the rule based translation of java code to COBOL code, as many developers today are unaware of COBOL language which is used in many legacy systems their maintainance is a challenge and also LLMs perform bad in understanding and fixing bugs in COBOL code. So our tool helps the developers to write code in java and convert it to cobol and use it for maintainance purposes. Also using this tool we can create datasets for COBOL and these datasets can be used to develop other tools as well as to train the LLMs and making LLMs capable to fix bugs in cobol codes, understand and generate good COBOL codes.

Results

We created a Java Dataset of 61 programs using Gpt 4'o to test our tool and we calculated the accuracy of mapping each construct we implemented and then found the weighted average to calculate the tool accuracy and it is found to be 98.5% reflecting the tool's strong performance in code translation from Java to COBOL.

Demo Video

TBD

Contributors

Srikrishna Kidambi, Sai Krishna Brahmajosyula, Sridhar Chimalakonda