- Milos Obrenovic (1041/2024)
- Lazar Kracunovic (1038/2024)
This project implements a translator from C++ to Python based on Abstract Syntax Trees (ASTs).
The goal is to demonstrate how formal grammars and AST-based approaches can be applied to automatic program translation between programming languages.
- ANTLR4 Grammar for parsing C++14 source code.
- AST Hierarchy in Java: nodes for expressions, statements, declarations, loops, and functions.
- AST Builder: a visitor that walks the ANTLR parse tree and constructs the internal AST model.
- Code Generation Module: traverses the AST and produces equivalent Python code.
- Testing Framework: compares the output of compiled C++ programs with the output of translated Python code, ensuring correctness.
- Java 21+
- Gradle (build tool, included via
build.gradle
) - ANTLR4 (plugin included in the build)
- Python 3.10+ (to run translated programs)
- G++ (optional, for compiling original C++ tests)
./gradlew build
Run all tests:
./gradlew testTranslator
To run on individual file:
- Add correct .cpp file in tests/input
- In example.java modify line
CharStream charStream = CharStreams.fromFileName("src/main/tests/input/example.cpp");
- Run
./gradlew example