This is a starting point for Zig solutions to the "Build your own Interpreter" Challenge.
This challenge follows the book Crafting Interpreters by Robert Nystrom.
In this challenge you'll build an interpreter for Lox, a simple scripting language. Along the way, you'll learn about tokenization, ASTs, tree-walk interpreters and more.
Before starting this challenge, make sure you've read the "Welcome" part of the book that contains these chapters:
- Introduction (chapter 1)
- A Map of the Territory (chapter 2)
- The Lox Language (chapter 3)
These chapters don't involve writing code, so they won't be covered in this challenge. This challenge will start from chapter 4, Scanning.
Note: If you're viewing this repo on GitHub, head over to codecrafters.io to try the challenge.
This is a Turing-complete implementation of the Lox interpreter in Zig, following the classic phases of interpretation:
- Converts source code into tokens
- Handles identifiers, keywords, literals, and operators
- Provides detailed error reporting for invalid characters
- Builds Abstract Syntax Tree (AST) from tokens
- Implements recursive descent parsing
- Supports expressions, statements, and control flow
- Tree-walk interpreter that executes the AST
- Manages runtime environment and variable scoping
- Supports arithmetic operations, strings, and control flow
- Handles runtime error reporting
src/
├── main.zig # Entry point and command handling
├── scanner.zig # Lexical analysis
├── parser.zig # Syntactic analysis
├── interpreter.zig # Execution engine
└── types.zig # Core type definitions
- Variable declarations and assignments
- Arithmetic and logical operations
- Control flow (if, while, for)
- Runtime error handling