This project is a Java implementation of the Lox interpreter, built as part of the Codecrafters "Build your own Interpreter" challenge. The challenge follows the book Crafting Interpreters by Robert Nystrom.
Lox is a simple scripting language. This interpreter project covers various aspects of language implementation, including tokenization, parsing, and interpreting the abstract syntax tree (AST).
- Tokenization –
Scannerconverts source code into tokens (keywords, identifiers, literals, operators). - Parsing –
Parserconverts tokens into an AST, handling expressions and statements. - AST –
ExprandStmtdefine the structure of Lox code. - Interpretation –
Interpreterwalks the AST to execute code (variables, functions, control flow). - Error Handling – Handles syntax and runtime errors.
- Environment & Scope –
Environmentmanages nested scopes for variables and functions. - Function Calls –
Functionsupports parameter passing and return values. - Native Functions – Includes
clockto return the current time.
To run the interpreter locally, use the your_program.sh script:
your_program.sh run <filename>| Command | Description |
|---|---|
tokenize <filename> |
Tokenizes the source code and prints the tokens. |
parse <filename> |
Parses the source code and prints the AST. |
evaluate <filename> |
Evaluates a single expression and prints the result. |
run <filename> |
Runs the entire Lox program. |
To run a Lox program:
your_program.sh run test.lox- This project follows the book Crafting Interpreters by Robert Nystrom. Special thanks to Codecrafters for providing the challenge.
- For more details, visit the Codecrafters Challenge page.