An implementation of the LOX language from the book Crafting Interpreters.
This JLOX implementation is written in Java 17 and uses Maven as a build tool.
In order to build the project, run the following command:
./mvnw clean package
LOX has a Prompt mode and a File mode.
java -jar target/jlox-1.0-SNAPSHOT.jar
java -jar target/jlox-1.0-SNAPSHOT.jar <file>
Of course replace with the path to the file you want to run.
You can try also the files in the resources folder
So far with the interpreter, you can make some arithmetic calculations:
314 == "pi"
420 + 69
More complex operations will be implemented further on.
Variables can be dynamically declared:
var a = "tuvieja";
Also, if a variable exists, can have its value replaced:
a = "nolongertuvieja";
Similarly, as Java you can declare an if like this:
if ( 1 < 2 ) {
print true;
} else {
print false;
}
print "hi" or 2;
hi
print nil or "yes";
yes
{
var i = 0;
while (i < 10) {
print i; i = i + 1;
}
}
for (var b = 1; a < 10000; b = temp + b) {
print a; temp = a; a = b;
}
You can try functions with this fibonacci example:
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);}
We all have lives and so do I. I have not implemented the whole language yet, but I am working on it.
So far I have implemented the following:
- Scanner
- Parser
- Interpreter
- Statements and State
- Control Flow
- Functions
Coming next:
- Chapter 12: Classes