An interpreter for the Lox language, written in Java by following along with Bob Nystrom's "Crafting Interpreters".
From the root folder, build using gradle ./gradlew build
and launch using ./gradlew app:run -q --console=plain
.
While the book itself provides source code for the interpreter, this implementation adds the following suggested features/"challenges" from the book:
- Multiline C-style comments:
/* */
. - Reverse Polish Notation Printer: (1 + 2) * (4 - 3) --> 1 2 + 4 3 - *
- C-style comma operator
- Ternary conditional (could be buggy)
- String + non-string converts non-string to string and performs string concatenation (e.g. 5 + "hello")
- Division by zero generates runtime error.
- Error productions for binary operator at the beginning of an expression.
- Error messages show location of error:
Error: Unexpected "," in argument list.
15 | function(first, second,);
^-- Here.
- Blobs of invalid characters produce a single error message.