Skip to content
forked from lucasig11/jlox

Lox language interpreter written in Rust.

Notifications You must be signed in to change notification settings

sria91-rlox/jlox

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lox programming language

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

Examples

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(); 

Run

Cargo is required.

cargo install --git https://github.com/lucasig11/jlox

# Run the REPL
jlox

# Run some script
jlox examples/script.jlox

Differences from the original implementation

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 }

Builtin functions

  • 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;

About

Lox language interpreter written in Rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%