Loading...

Build your own Interpreter

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

Start Building
interpreter
C
interpreter
C++
interpreter
C#
interpreter
Gleam
interpreter
Go
interpreter
Java
interpreter
JavaScript
interpreter
Kotlin
interpreter
OCaml
interpreter
PHP
interpreter
Elixir
interpreter
Odin
interpreter
TypeScript
interpreter
Clojure
interpreter
Python
interpreter
Rust
interpreter
Zig

This challenge requires a CodeCrafters Membership.

You're welcome to study the full challenge structure and stage instructions for free. A membership is needed for submitting code and viewing solutions.

Want to try a free challenge? Try Build your own Kafka — it's free during beta.

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.

Base Stages

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.

Scanning: Empty file
Very easy
We'd expect a proficient developer to take < 5 minutes to complete this stage.
Scanning: Parentheses
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Braces
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Scanning: Other single-character tokens
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Lexical errors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Assignment & equality Operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Negation & inequality operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Relational operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Division operator & comments
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Whitespace
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: Multi-line errors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scanning: String literals
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Scanning: Number literals
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Scanning: Identifiers
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Scanning: Reserved words
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Parsing Expressions

This extension covers chapters 5 & 6 of the book (Representing Code & Parsing Expressions).

In this extension, you'll add the ability to parse expressions.

Booleans & Nil
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Number literals
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
String literals
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Parentheses
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Unary Operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Arithmetic operators (1/2)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Arithmetic operators (2/2)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Comparison operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Equality operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Syntactic errors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Evaluating Expressions

This extension covers chapters 7 of the book (Evaluating Expressions).

In this extension, you'll add the ability to evaluate expressions.

Literals: Booleans & Nil
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Literals: Strings & Numbers
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Parentheses
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Unary Operators: Negation & Not
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Arithmetic Operators (1/2)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Arithmetic Operators (2/2)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
String Concatenation
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Relational Operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Equality Operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Runtime Errors: Unary Operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Runtime Errors: Binary Operators (1/2)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Runtime Errors: Binary Operators (2/2)
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Runtime Errors: Relational Operators
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Statements & State

This extension covers chapters 8 of the book (Statements & State).

In this extension, you'll add the ability to add internal state to your interpreter & produce output.

Print: Generate output
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Print: Multiple statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Expression statements
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Variables: Declare variables
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Variables: Runtime Errors
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Variables: Initialize variables
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Variables: Redeclare variables
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.
Assignment operation
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Block syntax
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Scopes
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Control Flow

This extension covers chapters 9 of the book (Control Flow).

In this extension, you'll add the ability to handle control flow statements like if/else, while & for.

If statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Else statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Else-if statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Nested if statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Logical OR operator
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Logical AND operator
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
While statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
For statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Syntactic errors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Functions

This extension covers chapters 10 of the book (Functions).

In this extension, you'll add the ability to handle lox native functions & user-defined functions.

Native functions
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Functions without arguments
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Functions with arguments
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Syntax errors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Return statements
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Higher order functions
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Runtime errors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Function scope
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Closures
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.

Resolving & Binding

This extension covers chapters 11 of the book (Resolving & Binding).

In this extension, you'll add the ability to semantically analyze variable declarations and resolve variable bindings at compile time.

Identifier Resolution
Hard
We'd expect a proficient developer to take more than 1 hour to complete this stage.
Self Initialization
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Variable Redeclaration
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Invalid Return
Easy
We'd expect a proficient developer to take 5-10 minutes to complete this stage.

Classes

This extension covers chapters 12 of the book (Classes).

In this extension, you'll add the ability to handle lox classes, instances, constructors and methods.

Class Declarations
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Class Instances
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Getters & Setters
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Instance Methods
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
The 'this' keyword
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Invalid usages of 'this'
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Constructor calls
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Return within constructors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.

Inheritance

This extension covers chapters 13 of the book (Inheritance).

In this extension, you'll add the ability to handle class inheritance, method overriding and the super keyword.

Class Hierarchy
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Inheriting Methods
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Overriding Methods
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Inheritance errrors
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
The super keyword
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.
Invalid Usages of the super Keyword
Medium
We'd expect a proficient developer to take 30 minutes to 1 hour to complete this stage.