Lox Playground
What is Lox?
Lox is a programming language by Bob Nystrom written for the book Crafting Interpreters. It is an excellent book that teaches how to build lexers, parsers and interpreters. After reading the book and having implemented the interpreter for Lox in Java, I decided to make a playground for it which runs the code on the Java Interpreter for Lox hosted on a server.
Try Lox code
Enter Lox code below, then use the Run button. Tab moves to Run; Shift+Tab moves backward.
Run results
Documentation
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.