Skip to content

codewaseem/lox-compiler

Repository files navigation

progress-banner

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:

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.

Implementation Details

This is a Turing-complete implementation of the Lox interpreter in Zig, following the classic phases of interpretation:

1. Lexical Analysis (Scanner)

  • Converts source code into tokens
  • Handles identifiers, keywords, literals, and operators
  • Provides detailed error reporting for invalid characters

2. Syntactic Analysis (Parser)

  • Builds Abstract Syntax Tree (AST) from tokens
  • Implements recursive descent parsing
  • Supports expressions, statements, and control flow

3. Execution (Interpreter)

  • Tree-walk interpreter that executes the AST
  • Manages runtime environment and variable scoping
  • Supports arithmetic operations, strings, and control flow
  • Handles runtime error reporting

Project Structure

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

Features

  • Variable declarations and assignments
  • Arithmetic and logical operations
  • Control flow (if, while, for)
  • Runtime error handling

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •