Build your own Interpreter

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

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
Scanning: Parentheses
Scanning: Braces
Scanning: Other single-character tokens
Scanning: Lexical errors
Scanning: Assignment & equality Operators
Scanning: Negation & inequality operators
Scanning: Relational operators
Scanning: Division operator & comments
Scanning: Whitespace
Scanning: Multi-line errors
Scanning: String literals
Scanning: Number literals
Scanning: Identifiers
Scanning: Reserved words

Parsing Expressions

Booleans & Nil
Number literals
String literals
Parentheses
Unary Operators
Arithmetic operators (1/2)
Arithmetic operators (2/2)
Comparison operators
Equality operators
Syntactic errors

Evaluating Expressions

Literals: Booleans & Nil
Literals: Strings & Numbers
Parentheses
Unary Operators: Negation & Not
Arithmetic Operators (1/2)
Arithmetic Operators (2/2)
String Concatenation
Relational Operators
Equality Operators
Runtime Errors: Unary Operators
Runtime Errors: Binary Operators (1/2)
Runtime Errors: Binary Operators (2/2)
Runtime Errors: Relational Operators

Statements & State

Print: Generate output
Print: Multiple statements
Expression statements
Variables: Declare variables
Variables: Runtime Errors
Variables: Initialize variables
Variables: Redeclare variables
Assignment operation
Block syntax
Scopes

Control Flow

If statements
Else statements
Else-if statements
Nested if statements
Logical OR operator
Logical AND operator
While statements
For statements
Syntactic errors

Functions

Native functions
Functions: No arguments
Functions: With arguments
Functions: Syntax errors
Return statements
Higher order functions
Functions: Runtime errors
Global & local scope
Closures