Playground

Lox

Lox is the language Bob Nystrom builds in Crafting Interpreters, a book about writing lexers, parsers and interpreters. I worked through it and wrote my own interpreter for Lox in Java. Everything you run below is sent to that interpreter.

Lox editor

Examples
main.lox + Enter to run
Output

Press Run to send this program to the interpreter.

View source

Language reference

Everything Lox can do, with a snippet for each. Copy any of it into the editor above.

General

Lox's syntax is a member of the C family. It is a dynamically typed language. Braces { } denotes a block of code and // is used for comments.

Variables

Lox supports booleans, numbers, strings and nil. Variables can be declared with the 'var' keyword.

Arithmetic

Lox supports the following basic arithmetic operators.

Conditional

Lox supports if-else-if ladders.

Loops

Lox supports for loops and while loops.

Functions

You can create functions with the 'fun' keyword.

Classes

You can create classes with the 'class' keyword and initilaize them with the 'innit' method. 'this' keyword is used to refer to the current object

Inheritance

Lox supports single inheritance. When you declare a class, you can specify a class that it inherits from using '<' operator.