Skip to content

SmelJey/KotlinCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KotlinCompiler

Compiler for simplified subset of Kotlin language

Implemented:

  • Lexer,
  • Parser,
  • Semantic analyzer,
  • Interpreter.

You can check grammar on the special page

Notable differences from original Kotlin:

  • Only next built-in types are supported: 'Int', 'Double', 'Boolean', 'String', 'Array' and 'ClosedRange'. You can declare your own types via 'class' keyword;
  • Built-in types have only casts (toInt(), toString(), etc) and basic operators (+, -, &&, index operator for arrays, etc) as only available members;
  • String index operator is not supported;
  • Operator overloading is not supported;
  • 'in' and '!in' are only supported infix functions (for example, bitwise operators ('and', 'or', 'shl', etc) are not supported);
  • Every entity should be declared before the first usage;
  • Return type of every function should be explicit if it is other than 'Unit';
  • Visibility / abstract modifier, 'this' keyword, primary and secondary constructors, init block, nested classes are not supported;
  • Lambdas, function types, object literals and generics (other than ClosedRange and Array) are not supported;
  • Boolean ranges (yes, they are exist) and progressions (i.e. range with 'step' or 'downTo' keyword) are not supported;
  • Jumps (e.g. 'break', 'continue', 'return') can not be used as expressions.

Installation

Open .sln file in Visual Studio and build entire solution. The compiler executable (KotlinCompiler.exe) with Core.dll would lie in Debug / Release folder in the solution directory.

Usage

KotlinCompiler.exe [flags] <source file>

Next flags are supported:

  • '-l' or '--lexer-debug' -- show lexer's output (stream of tokens);
  • '-p' or '--parser-debug' -- show parser's output (syntax tree)
  • '-s' or '--semantics-debug' -- show semantics analyzer's output (semantics annotations on syntax tree and symbol table)

Tests:

Tests are implemented with Catch2. In order to launch interpreter tests, install the official Kotlin compiler (tested with native version) and build Compiler on Release configuration. Then you are ready to go.

Author

Yuriy Mikhalev - 3rd year student of Applied Mathematics and Informatics (Far Eastern Federal University)

About

Simplified Kotlin compiler (WIP)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published