JAVA2COB is a open-source tool that performs the rule based translation of Java code to COBOL.
JAVA2COB Github RepositoryThe tool has a GUI and this can be accessed by following the steps below:
git clone https://github.com/SrikrishnaKidambi/Java-to-COBOL.git
cd Java-to-COBOL
cd Antlr
javac -cp ".;antlr-4.13.2-complete.jar;javaparser-core-3.25.8.jar"Â *.java
javac -cp ".:antlr-4.13.2-complete.jar:javaparser-core-3.25.8.jar" *.java
cd ..
javac ToolGUI.java
java ToolGUI
in the tool's base directory.
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.
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.
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.
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.
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.
Srikrishna Kidambi, Sai Krishna Brahmajosyula, Sridhar Chimalakonda