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. So our tool aims to extend COBOL systems using Java.

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 through command line 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.
  7. We have also buit a website and an extension to access the tool at greater ease and can be found at the links below:

    1. Website: https://java2cob-rishalab.onrender.com/
    2. Extension: https://marketplace.visualstudio.com/items?itemName=SaiKrishnaBrahmajosyula.java-to-cobol-convertor

Tool 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.


Website:

elegant icons

Extension:

elegant icons

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) Evaluation of code translation:

    Once the cobol code is generate using GNU cobol we compiled and executed the code and similarly used java compiler for java code and compared the output to test the correctness of the tool.

    5) 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 and some intrinsic(library) functions available in cobol.

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 the performance of LLMs is not satisfactory in all the cases (which we mentioned in the tool paper in Evaluation section). So our tool aims to extend COBOL systems using Java. We picked Java as it stands to be one of the popular languages and also there are lot of java resources available.

Results

We created a Java Dataset of 101 programs partially with the help of 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.35% reflecting the tool's strong performance in code translation from Java to COBOL. Detailed breakdown of accuracy per each construct is provided in the tool paper.

Demo Video

Contributors

Srikrishna Kidambi, Sai Krishna Brahmajosyula, Sridhar Chimalakonda