Home

Awesome

Labyrinth

Labyrinth is a two-dimensional esoteric programming language. The source code resembles a maze which is traversed by the instruction pointer. Labyrinth has two main features setting it apart from most other languages: a) there are no control flow operators - control flow is determined solely by the layout of the maze - and b) the source code can be modified at runtime via cyclic shifts of rows and columns. The latter mechanic was inspired by the German board game Das verrückte Labyrinth.

Labyrinth is Turing-complete as any Brainfuck program can be translated to Labyrinth quite trivially.

This repository contains the language specification (below), a reference implementation in Ruby as well as a handful of example programs.

Overview

The source code consists of single-character instructions and is interpreted as a 2D grid. The instruction pointer starts at the first known character in the file (in reading order) going right. All unknown characters are considered walls.

As for data structures, Labyrinth has two stacks, called main and auxiliary. They both start empty but the bottoms of the stacks are treated as an infinite number of zeroes (so if you try to pop from or operate on an empty stack you will get zeroes).

Control Flow

Labyrinth is interpreted in a simple loop. At each step, the command under the instruction pointer is executed, then the new movement direction is determined, and then the instruction pointer moves one cell in that direction. The edges of the grid are not connected.

The instruction pointer will generally follow "corridors" of instructions. Junctions can be used for non-trivial control flow. How the new movement direction is determined depends on the number of available steps (i.e. number of direct neighbours with known commands):

Commands

With the exception of v Labyrinth uses only non-letter commands. Spaces are reserved as walls and [ and ] have no function yet but may be added later (that is, they are currently also treated as walls).

General

Arithmetic

All arithmetic operators work with the main stack.

Stack manipulation

I/O

These also operate on the main stack.

Grid manipulation

The four trickiest commands are <^>v:

Comments

Labyrinth doesn't have a dedicated comment syntax. However, spaces and all letters except lower-case v are considered walls, so you can use them freely around your code to add comments. Furthermore, you can use arbitrary characters (even recognised ones) as long as they are not reachable, e.g. by separating them from the actual program by a layer of walls. However, in this case be careful if you use the grid manipulation commands as they might bring your comments in contact with your actual program.

Interpreter features

The interpreter has a verbose debug mode (like an additional debug level beyond activating ' commands) which can be switched on with the command-line flag -D. If this flag is set, the interpreter will print detailed diagnostic information after every tick of the program.