Skip to content

vincent-prz/rox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rox

Tree walk interpreter for the Lox language in Rust, following the book Crafting Interpreters. Work in progress.

Features

  • Evaluate expressions (upon numbers, strings and booleans)
  • Variable declaration and assignment
  • Scopes
  • Control Flow (if statements, while and foor loops)
  • Functions
  • Closures
  • Classes
  • Inheritance

Examples

Fibonacci numbers (naive implementation)

fun fib(n) {
    if (n < 2) {
	return n;
    }
    return fib(n - 1) + fib(n - 2);
}

var result = fib(10);
print(result);

Closures

fun makeCounter() {
    var i = 0;
    fun count() {
        i = i + 1;
        print i;
    }
    return count;
}

var counter = makeCounter();
counter(); // 1
counter(); // 2

OOP and inheritance

class Doughnut {
  cook() {
    print "Fry until golden brown.";
  }
}

class BostonCream < Doughnut {}

BostonCream().cook();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages