Interpreter for the Lox language implemented in C++, with additional features.
Implements vanilla Lox according to Chapters 4-13 of Crafting Interpreters by Bob Nystrom, as well as the following extra challenges:
- Chapter 4 (Scanning):
- C-style block comments
- Chapter 6 (Parsing):
- Comma operator
- Ternary operator
- Error productions for binary operators
- Chapter 7 (Evaluating Expressions)
- Type coercion for string concatenation
- Divison by 0 error
- Modulo operator
- Chapter 8 (Statements and State)
- REPL support for both expressions and statements
- Runtime error for unassigned variables
- Chapter 9 (Control Flow)
- Break and continue statements
- Chapter 10 (Functions)
- Anonymous functions
- Chapter 11 (Resolving and Binding)
- Resolver error for unused local variables
- More efficient environment representation via resolver indexing and vectors
- Chapter 12 (Classes)
- Static methods and fields via metaclasses
- Getter members
- Chapter 13 (Inheritance)
superkeyword allows access to superclass fields in addition to methods
Build the interpreter:
make lox
- Interpreter:
./lox [path to program file] - REPL:
./lox
Run the tests:
make test
Add new tests to the tests/ directory as follows:
[test_name].loxcontains the Lox program[test_name].expectedcontains the expected program output