Skip to content

cachebag/rlox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rlox 🦀

Yet another implementation of Lox in Rust, via Robert Nystrom’s Crafting Interpreters

This is (an attempt at) a faithful, idiomatic re-implementation of Lox (which was built in Java) in Rust. More than anything, it's an exercise.

Usage

  1. Clone and build
git clone https://github.com/cachebag/rlox.git
cd rlox
cargo build --release
  1. Run REPL (currently stateless)
cargo run

> print "Hello, world!";
Hello, World!

> var msg = 10 != 100 ? "true" : "false"; print msg;
true
  1. Run a lox file
// examples/recursive_fib.lox
fn fib(n) {
  return n <= 1 ? n : fib(n - 2) + fib(n - 1);
}

for (var i = 0; i < 20; i = i + 1) {
  print fib(i);
}
cargo run examples/recursive_fib.lox

0
1
1
2
3
5
8
13
21
...

Debug

You can print the tokens of a given file or stdin input.

cargo run show-tokens <file> # Scans the given file and prints its tokens.

cargo run show-tokens - # Reads from stdin and prints tokens.

You can also print the parsed AST for a given file or input.

cargo run show-ast <file> [output.txt] # Prints the parsed AST for the given file. (defaults to ast_output.txt if no name is given

cargo run show-ast - [output.txt] - # Stdin 

Resources

About

Rust implementation of Lox from "Crafting Interpreters" by Robert Nystrom.

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages