Golox is a general purpose programming language. It is a Go implementation of Lox (by Robert Nystrom) with some differences
To run the REPL, simply type
go run .
To execute a file in the current directory use the -f flag
go run. -f test.glx
Demonstrating: if statements, functions, for loops, and recursive function calls
fun fib(n) {
if (n <= 1) return n;
return fib(n - 2) + fib(n - 1);
}
for (var i = 0; i < 20; i = i + 1) {
print fib(i);
}
Output
0
1
1
2
..
4181
Demonstrating the use of Closures
fun makeCounter() {
var i = 0;
fun count() {
i = i + 1;
print i;
}
return count;
}
var counter = makeCounter();
counter(); // "1".
counter(); // "2".
Output
1
2
Add the flag -d to enable debug mode
go run . -d
It looks for the file, passed with the -f flag, in project root
go run . -f test.glx