This project is a Rust-based interpreter for the "Build Your Own Interpreter" Challenge from Codecrafters, following the structure and concepts presented in the book Crafting Interpreters by Robert Nystrom.
In this challenge, the goal is to build an interpreter for the Lox language, a simple scripting language. The project helps solidify core concepts of interpreters, including tokenization, abstract syntax trees (ASTs), and tree-walk interpreters.
- Tokenization: Handles the process of breaking down input strings into meaningful symbols (tokens) used by the interpreter.
- Parsing: Constructs an Abstract Syntax Tree (AST) from the tokens, forming the structure of the code for interpretation.
- AST Printer: Outputs the structure of parsed expressions for debugging and testing.
- Tree-Walk Interpreter (Coming Soon): Future work will include a tree-walk interpreter that directly interprets the Abstract Syntax Tree (AST) and executes the code.
-
Install dependencies: This project uses Rust. Ensure that you have Rust installed by following the instructions here.
-
Tokenize a Lox file: To tokenize your input Lox code:
./your_program.sh tokenize tests/test.lox
- Parse a Lox file: To parse your input Lox code and generate the AST:
./your_program.sh parse tests/test.lox
This project is organized into several core modules:
- token: Responsible for handling the different types of tokens in Lox.
- parser: Builds the Abstract Syntax Tree (AST) from tokens.
- ast_printer: A utility for visualizing the AST.
- A tree-walk interpreter will be added, allowing direct interpretation and execution of the AST.
- Support for functions, classes, and additional language features may be implemented to extend the Lox interpreter.
You can track my progress on the Codecrafters platform here.