Rune is a dynamically typed interpreted programming language inspired by Lox and built following concepts from the book Crafting Interpreters by Robert Nystrom. This interpreter is implemented in Go and is designed to be cross-platform, compiling into a statically linked binary.
- Dynamically typed language with a simple syntax
- Supports expressions, statements, variables, and functions
- Built-in functions for array manipulation, JSON parsing, and timing
- Recursive descent parser and tree-walk interpreter
- Cross-platform, compiles to a single binary
To build the interpreter, you need to have Go installed. Clone the repository and run:
make buildThis will generate an executable binary named rune in the project directory.
You can execute Rune scripts using the run command:
./rune run script.rnAlternatively, you can specify the file in the Makefile and use:
make runThe Rune interpreter supports the following commands:
tokenize— Tokenizes the given input file.evaluate— Evaluates a single expression from the file.run— Executes the entire program from the input file.
Example usage:
./rune run program.rnTest Framework with tests suites is stolen from Ben Hoyt and patched.
make testTo run a specific test or filter tests by category:
python3 test.py <filter>For example, to run only the arrays tests:
python3 test.py arraysRune provides several built-in functions:
len(arr)— Returns the length of an array.append(arr, value1, value2, ...)— Appends values to an array and returns the new array.json(url)— Fetches and parses JSON from a URL, error handling is not implemented.clock()— Returns the current time in seconds.
Here’s a simple Rune script that calculates the sum of an array:
fun sumArray(arr) {
var total = 0;
for (var i = 0; i < len(arr); i = i + 1) {
total = total + arr[i];
}
return total;
}
print sumArray([1, 2, 3, 4, 5]);This project is open-source and follows the MIT license.
- Crafting Interpreters by Robert Nystrom
- Lox Programming Language
- Test Framework