The walk-tree interpreter
Original implementation: Crafting Interpreters book.
This implementation is not compatible with the original one, see the differences here.
Lox is an interpreted, dynamically typed, object-oriented, programming language designed by Robert Nystrom.
This was made for learning purposes, as an exercise to better understand the Rust programming language and compilers/interpreters in general.
Language features:
- Variables
- First-class functions
- Closures
- Classes
- Inheritance
- Control flow structures (if, while, for loop)
- Builtin functions
print "Hello, world!";
class Hello {
// Class constructor
init(world) {
self.world = world;
}
// Bound method
say() {
print "Hello" + this.world;
}
// Static method
static world() {
print "Hello static world";
}
}
// Prints "Hello static world"
Hello.world();
let hello = Hello("world");
// Prints "Hello world"
hello.say();
Cargo is required.
cargo install --git https://github.com/lucasig11/jlox
# Run the REPL
jlox
# Run some script
jlox examples/script.jlox
Functionality | Original | Ours |
---|---|---|
Inheritance | < |
extends |
Variable declaration | var |
let |
Function declaration | fun |
fn |
Integer types | double |
32-bit int and 64-bit float |
Comma operator | not implemented |
let a, b = 1, 2; |
Static methods | not implemented |
static |
Pipe operator | not implemented |
2 |> mul(2) |> sub(1) |
If statement | if (true) // some code |
if true { // some code } |
- Clock Returns the current system time as milliseconds.
Usage:
print clock();
- Read
Reads a line from
stdin
and returns as a string.
Usage:
print "write something: ";
let prompt = read();
print "you wrote: " + prompt;