Home

Awesome

motorway-lang

An esoteric programming language based around the British motorway network.

The Language

A Motorway program is a description of a route along the British (mainland) motorway network. Only motorways that form the main interconnected network are allowed. Any non-existent or unconnected motorway (e.g. M2) is a syntax error. Anything not of the form Mx or AxM (where x is a number) is ignored as a comment.

Certain motorways have special meanings, called commands. Other motorways merely serve to connect these commands. A program is valid only if the route it describes is physically possible (i.e. each motorway visited must connect to the next). The directionality of junctions is not considered when testing the validity of a route, nor is motorway status (or lack thereof) of connections at junctions between two motorways (e.g. you can change between the M1 and M69, even though in real life, this would involve leaving motorway restrictions and negotiating a roundabout before getting onto the M69). A motorway corresponding to a command can be visited without invoking its effect by placing the route number in brackets (e.g. M6 (M1) M69 visits the M1 with no side effects).

A program has access to a data stack, which most of the commands manipulate. The stack comprises an unbounded number of 8-bit unsigned cells, which wrap on overflow. Note that in practice, there will be an upper bound on the size of the stack, but this is not defined by the language.

Commands

Other Motorways

The Interpreter

This repository contains a Python implementation of the language. This relies on the third-party package fixedint which must be installed before using the interpreter (e.g. using pip). Of course, Python (3.9+) must also be installed on the system to use the interpreter.

With fixedint installed, you can run the interpreter by running the script motorway.py:

python motorway.py [file]

The argument file, if provided, determines the source code file to be interpreted. Alternatively, you can omit it to enter an interactive REPL session. The recommended filename extension for Motorway files is *.mway, although any extension may be used. The extension must be included when invoking the interpreter.

Project Structure

Source code is (mainly) found in the src directory. A single script motorway.py is provided in the project root to make it easier to use as a command line tool.

The network used to validate routes can be found in data/network.json.

The tools directory contains scripts used to automatically generate various parts of the project. These should not need to be invoked in normal running of the interpreter (although running them shouldn't break anything either).

The contents of these subdirectories are described in more detail in their individual READMEs.