rlox
is an interpreter for the Lox programming language, implemented in Rust. This project is inspired by the Crafting Interpreters book by Robert Nystrom and follows its principles to build a tree-walking interpreter. The goal of rlox
is to provide a simple, expressive scripting language while demonstrating core interpreter concepts, all while taking advantage of Rust’s powerful safety and performance features.
- Lexical Analysis:
rlox
includes a tokenizer that breaks down source code into tokens, categorizing elements like keywords, identifiers, operators, and literals. - Parsing: A recursive descent parser processes tokens into an Abstract Syntax Tree (AST) to represent code structure.
- Interpretation:
rlox
executes code by evaluating the AST directly, supporting basic control flow, expressions, functions, and variable scope. - Error Handling: Detailed error messages help developers debug their
rlox
scripts, with syntax and runtime error reporting.
Lox programs for rlox
use the .rlox
extension.
To build and run rlox
, you will need:
- Rust installed (recommended version: 1.50 or later)
-
Clone the repository:
git clone https://github.com/will-create/rlox.git cd rlox
-
Build the project:
cargo build --release
-
Run the interpreter with an example
.rlox
file:cargo run --release examples/script.rlox
You can run rlox
files directly from the command line:
rlox path/to/script.rlox
Here’s a simple .rlox
script:
// Hello World in rlox
print "Hello, world!";
// Variables and expressions
var x = 10;
print x * 2;
// Functions
fun greet(name) {
print "Hello, " + name + "!";
}
greet("Rustaceans");
- src: Contains all source code files for
rlox
, including lexer, parser, AST definitions, and interpreter logic. - examples: Sample
.rlox
files showcasing various language features. - tests: Unit and integration tests.
Contributions are welcome! If you would like to contribute to rlox
, feel free to fork the repository, make changes, and submit a pull request. Please ensure all code passes the tests before submitting.
This project is licensed under the MIT License.