/cobol-to-java-transpiler

A Cobol to Java Transpiler

Primary LanguageKotlinGNU General Public License v3.0GPL-3.0

actojat

Build Status

A Cobol to Java transpiler.

Motivation

Companies have large legacy code bases which are hard to migrate manually. The Amazing Cobol To Java Transpiler is meant to explore one possible solution: automatic source code transpilation. Right now this project is work in progress, focusing on COBOL85 code bases only.

How to build it

Install a Java SE Development Kit as well as Apache Maven. Clone or download this repository, and build by running:

$ mvn install

How to run it

To transpile a single file of COBOL code run:

$ java -jar actojat-cli/target/actojat.jar /path/to/test-source-helloworld.cob TestName2 my.base.pckg COBOL /tmp/ false

Which language features are supported?

Actojat is still work in progress. The following table provides you with an overview, which language features of the COBOL85 language standard are already supported:

Feature (Keyword) Description Implemented? Sample COBOL code Generated Java Code
Conditional operators Greater, lesser, ... yes conditional.cob IfThenElseAndConditions.java
IF .. THEN ... ELSE Common branching yes conditional.cob IfThenElseAndConditions.java
PERFORM ... TIMES For-loops yes performtimes.cob PerformTimes.java
PERFORM ... UNTIL While-loops yes performuntil.cob PerformUntil.java
PERFORM ... VARYING Multi-var. For-loops no ... ...
PICTURE Variable declaration yes (partially) ... ...
MOVE Assignment no ... ...
... ... no ... ...

How does it work?

Actojat uses ANTLR for some of the heavy lifting: at the transpiler's heart lies a grammar file that describes the COBOL85 standard in an ANTLR-specific dialect of common BNF, ANTLR's Maven plugin is used to generate parser and tokenizer classes.

With these parser and tokenizer classes an AST for a given COBOL source file is then created. The CobolVisitor then creates an intermediate representation of the corresponding Java program from which the actual Java code is generated.

A module that implements support for ANSI C transpilation was added only to guarantee that the transpiler infrastructure has at least some degree of generality.