A tree-walk interpreter for the lox language as described in the book "Crafting Interpreters" written in Go.
It can execute lox scripts from a given file or can be launched in REPL mode:
lox <file-name> # Run from a file
lox # Start the REPL
- Strings can be compared lexicographically using the comparison operators
- Ternary operator (
:?
) break
andcontinue
statementsassert
statement
clock()
: Returns the time since January 1 1970, 00:00:00 (UNIX-epoch) in secondssleep(<time-in-seconds>)
: Pause execution of the script for the given timestring(<value>)
: Convert a Lox object to its string representationlen(<string>)
: Calculate the length of a string in bytesinstanceof(<instance>, <class>)
: Check whether an instance is of a specific class.hasattr(<instance>, <name>)
,getattr(<instance>, <name>)
,delattr(<instance>, <name>)
andsetattr(<instance>, <name>, <value>)
: Functions for manipulating instance attributes
fun fib(n) {
if (n <= 1) return 1;
return fib(n - 1) + fib(n - 2);
}
for (var i = 0; i < 20; i = i + 1) {
print fib(i);
}
From the project root directory run:
go build