Skip to content
/ klox Public

Simple interpreter of toy programming language called Lox.

Notifications You must be signed in to change notification settings

And1sS/klox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Klox

A simple interpreter of toy programming language called Klox, based on lox.

Language includes features such as variables, functions and classes.
You can check web version at https://lightwood13.github.io/loxjstest/

Some code examples:

  • variables, functions and clock() builtin
fun fib(n) {
    if (n == 0) return 0;
    if (n == 1) return 1;
    return fib(n - 1) + fib(n - 2);
}

var before = clock();
print fib(20);
var after = clock();
print after - before;
  • loops
var a = 0;
var b = 1;
var isEven = true; // to overcome absence of % operator
for (var i = 0; i < 50; i = i + 1) {
    var sum = a + b;
    print sum;
    if (isEven) {
      a = sum;
    } else {
      b = sum;
    }
    isEven = !isEven;
}
  • closures
fun makeCounter() {
    var a = 1;
    fun counter() {
        a = a + 1;
        print a;
    }
    return counter;
}

var a = 2;
var counter = makeCounter();
counter();
counter();

About

Simple interpreter of toy programming language called Lox.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages