An Interpreter of Kotlin language is defined by:
- A lexer that turns a sequence of characters (source program) into a sequence of tokens
- A parser that takes the previous sequence of tokens and produces an abstract syntax tree (AST)
- An interpreter (evaluator) that traverses the AST and executes the code line by line
Via PyCharm:
- Execute
main.py - Insert a number indicating the test case you want to interpret (from 0 to 6)
Via Terminal (write the following commands):
cd path-to-project-directory- python main.py
- Insert a number indicating the test case you want to interpret (from 0 to 6)
N.B.: Test cases 3, 4 and 5 present errors
- Linux/MacOS:
pip install pyinstaller
pyinstaller --onefile --hidden-import=Interpreter --hidden-import=Parser --hidden-import=Lexer --add-data "Tests/*:Tests" -n Interpreter main.py
- Windows:
pip install pyinstaller
pyinstaller --onefile --hidden-import=Interpreter --hidden-import=Parser --hidden-import=Lexer --add-data "Tests/*;Tests" -n Interpreter main.py
Kotlin grammar: https://kotlinlang.org/docs/reference/grammar.html
- Boolean
- Integer
- String
- Addition (
+) - Subtraction (
-) - Multiplication (
*) - Division (
/)
- Logical and (
&&) - Logical or (
||) - Logical not (
!)
- Equal to (
==) - Not equal (
!=) - Greater than (
>) - Less than (
<) - Greater than or equal to (
>=) - Less than or equal to (
<=)
if (...) {...} else {...}
while (...) {...}for (i in ...) {...}
println(...)(O)readLine(...)(I)
- Functions
- Comments and Whitespaces (ignored during execution)
PLY (Python Lex-Yacc): https://ply.readthedocs.io/en/latest/
Simple Colors: https://pypi.org/project/simple-colors/
PyInstaller: https://pyinstaller.org/en/stable/
Students:
-
Fioretti Maria Lucia (590016, m.fioretti1@studenti.poliba.it)
-
Preziosa Alessia (590012, a.preziosa2@studenti.poliba.it)