This is a translator of Java programming language to EOLANG programming language.
-
Make sure you have installed:
- Java 16+ (make sure command
java -version
shows 16+ version of Java in terminal if you have multiple Java version installed) - Maven 3.8+ to run tests (be aware of possible conflicts of the latest versions of Maven and Java on some OSs)
- ANTLR4 4.9.3 (if you want to build the parser on your own. If you don't have ANTLR, you still can build project using bundled version of parser.)
- Java 16+ (make sure command
-
Clone the repo into your folder:
HTTPS:
git clone https://github.com/polystat/j2eo.git cd ./j2eo
or SSH:
git clone [email protected]:polystat/j2eo.git cd ./j2eo
-
Build the project:
./build.sh
- See the troubleshooting section in case of problems
-
After build process, j2eo.jar file will appear in the project root folder (
./j2eo
). With this file, is it possible to translate .java files or packages to .eo packages. Run:java -jar j2eo.jar <source .java file or directory with Java files> -o <output directory>
to get the translation.
For example,
java -jar j2eo.jar src/test/resources/SimpleTest.java -o output_eo
or
java -jar j2eo.jar src/test/resources/polystat_tests/test1 -o output_eo
You can also use yegor256/j2eo image for Docker:
$ docker run -v $(pwd):/eo yegor256/j2eo hello.java --target output
This command will translate hello.java
in the current directory, saving the output to output/
subdirectory.
Hadoop is a large Java project (contains ~1.8M lines of code as of time of writing this). We included it as a benchmark of the translator.
Repository contains a script to build J2EO, download Hadoop repo and run J2EO on it.
Usage:
./test-hadoop.sh
It will download zipped hadoop
and unpack it (in a separate folder) into ../j2eo-data
relative to the project's root. Next, it will put the If you no more need that folder, run
rm -rf ../j2eo-data
This project is a part of Polystat project, the goal of which is to statically analyze different languages using EOLANG, the implementation of phi-calculus. In order to do that, the first step is to convert source language into EO. This particular repository contains translator from Java to EO.
Q: Why do we implement yet another Java parser?
A: Publicly available parsers only support older versions of Java, while we aim to support the latest version ( currently 16). Thus, we had to create our own parser.
Also in recent versions, external Java grammar implemented in ANTLR was added as an alternative. It claims to support Java 17, and it does, as for our testing on big projects.
Q: Why do we implement EO AST?
A: Working with AST instead of raw strings allows utilization of Java compiler's type checking to minimize amount of bugs in our code. It is also much easier to work with abstraction layer than with strings.
- First, the Java source code files are parsed recursively.
- Then, for each file, translator converts Java AST to EO AST.
- Then, EO AST is printed out as a source code to output directory in the same directory structure.
Make sure you have these in sync (mentioning (not pointing to) the same jdk
directory)
which java
which javac
- configure alternatives in case of mismatch (link)
echo $JAVA_HOME
.java files:
Translations:
We use Java language specification document as a foundation for Java feature hierarchy.
Java 16 language specification: see .pdf file
###Ch. 4 - Types, Values, and Variables
###Ch. 5 - Conversions and Contexts
###Ch. 7 - Packages and Modules WIP
- Method class member: Java to EO
- Field initialization: Java to EO
- Method declaration: Java to EO
- Inner class: Java to EO
###Ch. 14 - Block Statements, and Patterns
- Left-hand operands are evaluated first: Java to EO
- Integer literal: Java to EO
- Complex parenthesized expression: Java to EO
- Creation of a simple integer array: Java to EO
- Postfix increment: Java to EO
- Unary plus operator: Java to EO
- Multiplication operator: Java to EO
- Variable right shift: Java to EO
- Greater operator: Java to EO
- Assignment operator: Java to EO