This project is assignment for Sungkyunkwan University's PL class
It provides the ability to translate some of Kotlin's basic syntax into JAVA Language
(Spring 2019)
KotlinLexer.g4
KotlinParser.g4
KotlinLexer.java
KotlinParser.java
KotlinParserBaseListener.java
KotlinParserListener.java
1. Kotlin2Java.java : Main Class
Main class of this project. It starts program flow like
- receives input file & outpu-t file name from commandline argument. If missing, exit program
- Antlr4 creates parse tree, walker and attaches them to
KotlinListener
. - Check if output file name is in commandline argument. If not, output file name is automatically fixed as
"output.java"
- Walker walks from root using listner.
2. KotlinListener.java : Listener Class
Listener class, contains functions that respond when entering and exiting each token.
Structure is automatically implemented by Antlr4
It manages tokens using stack
.
Whenever enter a token, it is entered into the stack.
Also it handles expressions using KotlinExprForm
3. KotlinExprForm.java : Expr form Class
Super class for variable expression handling classes.
Its child class is as follow:
KotlinCallExprForm
: Handling callable expressionsKotlinDotExprForm
: Handling expressions containing dot(sign of decimal, properties, etc..)KotlinForExprForm
: Handling 'for' expressionsKotlinIdxExprForm
: Handling array expressionsKotlinIExprForm
: Handling 'is' expressionsKotlinIfExprForm
: Handling 'if' expressionsKotlinWhileExprForm
: Handling 'while' expressions
4. KotlinExprStacks.java : Expression Stack Class
This class is for stacks managing expressions
5. KotlinFunDeclForm.java : Function Expr Class
This class handles function structures.
6. KotlinConst.java : Const Class
Const variables are defined in this class
7. KotlinIDStackJob.java : Id stack manager Class
8. KotlinMultiVarDeclForm.java : Parenthesis making Class
9. KotlinUtils.java : Util Class
This class contains some functions used for several situations.
cngType
: Converts type of variables to make JAVA compiler can readchkType
: Checks type of variables, especiallylistOf
, and callchkDetail
functionchkDetail
: Specifically inferences the type of variable - Integer, String, DoublecngListOf
: Changes listOf structure into square bracket in specific case.