Loading...

Build your own Interpreter

Learn about tokenization, ASTs, tree-walk interpreters and more.

Start Building
interpreter
Go
interpreter
Python
interpreter
Rust
interpreter
Kotlin
interpreter
Java
interpreter
Gleam
interpreter
OCaml
interpreter
Zig
interpreter
JavaScript
interpreter
C
interpreter
C++
This challenge is free to try when it's in beta. We keep challenges in beta for a few weeks to gather feedback.

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.

Stages

Scanning: Empty file
Login via GitHub to view this stage
Scanning: Parentheses
Login via GitHub to view this stage
Scanning: Braces
Login via GitHub to view this stage
Scanning: Other single-character tokens
Login via GitHub to view this stage
Scanning: Lexical errors
Login via GitHub to view this stage
Scanning: Assignment & equality Operators
Login via GitHub to view this stage
Scanning: Negation & inequality operators
Login via GitHub to view this stage
Scanning: Relational operators
Login via GitHub to view this stage
Scanning: Division operator & comments
Login via GitHub to view this stage
Scanning: Whitespace
Login via GitHub to view this stage
Scanning: Multi-line errors
Login via GitHub to view this stage
Scanning: String literals
Login via GitHub to view this stage
Scanning: Number literals
Login via GitHub to view this stage
Scanning: Identifiers
Login via GitHub to view this stage
Scanning: Reserved words
Login via GitHub to view this stage

Parsing Expressions

Booleans & Nil
Login via GitHub to view this stage
Number literals
Login via GitHub to view this stage
String literals
Login via GitHub to view this stage
Parentheses
Login via GitHub to view this stage
Unary Operators
Login via GitHub to view this stage
Arithmetic operators (1/2)
Login via GitHub to view this stage
Arithmetic operators (2/2)
Login via GitHub to view this stage
Comparison operators
Login via GitHub to view this stage
Equality operators
Login via GitHub to view this stage
Syntactic errors
Login via GitHub to view this stage

Evaluating Expressions

Literals: Booleans & Nil
Login via GitHub to view this stage
Literals: Strings & Numbers
Login via GitHub to view this stage
Parentheses
Login via GitHub to view this stage
Unary Operators: Negation & Not
Login via GitHub to view this stage
Arithmetic Operators (1/2)
Login via GitHub to view this stage
Arithmetic Operators (2/2)
Login via GitHub to view this stage
String Concatenation
Login via GitHub to view this stage
Relational Operators
Login via GitHub to view this stage
Equality Operators
Login via GitHub to view this stage
Runtime Errors: Unary Operators
Login via GitHub to view this stage
Runtime Errors: Binary Operators (1/2)
Login via GitHub to view this stage
Runtime Errors: Binary Operators (2/2)
Login via GitHub to view this stage
Runtime Errors: Relational Operators
Login via GitHub to view this stage

Statements & State

Print: Generate output
Login via GitHub to view this stage
Print: Multiple statements
Login via GitHub to view this stage
Expression statements
Login via GitHub to view this stage
Variables: Declare variables
Login via GitHub to view this stage
Variables: Runtime Errors
Login via GitHub to view this stage
Variables: Initialize variables
Login via GitHub to view this stage
Variables: Redeclare variables
Login via GitHub to view this stage
Assignment operation
Login via GitHub to view this stage
Block syntax
Login via GitHub to view this stage
Scopes
Login via GitHub to view this stage

Control Flow

If statements
Login via GitHub to view this stage
Else statements
Login via GitHub to view this stage
Else-if statements
Login via GitHub to view this stage
Nested if statements
Login via GitHub to view this stage
Logical OR operator
Login via GitHub to view this stage
Logical AND operator
Login via GitHub to view this stage
While statements
Login via GitHub to view this stage
For statements
Login via GitHub to view this stage
Syntactic errors
Login via GitHub to view this stage

Functions

Native functions
Login via GitHub to view this stage
Functions without arguments
Login via GitHub to view this stage
Functions with arguments
Login via GitHub to view this stage
Syntax errors
Login via GitHub to view this stage
Return statements
Login via GitHub to view this stage
Higher order functions
Login via GitHub to view this stage
Runtime errors
Login via GitHub to view this stage
Function scope
Login via GitHub to view this stage
Closures
Login via GitHub to view this stage