This is the transpiler from Go source code to C++ source code written on Kotlin with the use of ANTLRv4.
From Go source code it builds an AST and then performs semantic analysis (typechecking). After that, it generates C++ source code.
To use the transpiler you need to have Java JRE installed on your device.
- Clone this project
- Run
./gradlew build
- Run
java -jar build/libs/jago.jar <path_to_go_code_file>
The last command has the following options:
-
You can specify just the path to Go source code file. Then the resulting C++ source code file will be generated in the current directory with name
output-cpp
.java -jar build/libs/jago.jar <path_to_go_code_file>
-
Besides the path to Go source code file you can also specify the path to resulting C++ source code file with the help of
-o
flag. If such file already exists it will be overriden.java -jar build/libs/jago.jar <path_to_go_code_file> -o <path_to_cpp_code_file>
Also, you can compile the resulting C++ source code:
- Put C++ the resulting source code file to
./generated-cpp/src/main/cpp/
. - Run
./gradlew generated-cpp:build
- Then you can find a compiled executable file in subdirectory of
./generated-cpp/build/exe/main/
The following Go constructs are not supported since there is no analogy in C++
- Goroutines
- Channels
- Slices
There are also features that is added to initial *Go grammar:
- Function overloading.
- Built-in
to_string(x)
function convertsx
to string.x
must be of a base type:int
,float64
,bool
, or pointer to these types.
- ANTLRv4 for generating a lexer and a parser for Go grammar.
- Kotlin as the main programming language
- Gradle as the main build tool
- JUnit 5 for testing the transpiler
- ShadowJar plugin for build a jar file
- During the Gradle build ANTLRv4 generates parser for input Go source code.
- Generated parser creates Concrete Syntax Tree of the given Go source code.
- Concrete Syntax Tree is converted to Abstract Syntax Tree.
- During the sematic analysis typechecking stage happens.
- Abstract Syntax Tree is translated to C++ source code.
Each stage is covered by tests. There are 76 tests in total.