An implementation of a tree walker interpreter for the Lox language from the book Crafting Interpreters by Bob Nystrom in Python. The interpreter can be used in two different modes:
- REPL - statements & expressions are passed through the terminal. statements are executed while expressions are evaluated and displayed.
- Passing a file as a command line argument.
- Added the Comma operator.
- Added the Ternary Operator.
- Error reporting on binary operators missing a left-hand operand.
- Added comparison operators to strings, chose not to allow comparison between mixed types.
- Added support for concatenating strings and numbers.
- Error report for division by zero.
- REPL now works in the following way: statements are executed, while expressions are evaluted and displayed.
- Accessing an undefined variable is now a runtime error.
- Added support for a break statement.
- Lambda functions are now supported.
- An unused & defined variable now raises a runtime error.
- Changed implementation of an environment to a list instead of a dictionary.
- Added metaclasses, and through them added support for class methods.
- Added support for get methods - more info here.
-
Added a native input command - read(message) - message will be printed as a prompt for the user.
-
Added a native array class which has the following methods:
set(i, value) - if i is not nil then set value at index i, otherwise append value to the end.
get(i) - returns the value at index i.
length() - returns the length of the array.
-
Changed print to be a native function.