Blank

From Esolang
Jump to navigation Jump to search

Blank is a stack-based esoteric programming language developed by Andrew Turley in 1997. Blank programs use single-character instructions contained within braces and numbers contained within brackets. Each number is an 'instruction' in the sense that 'executing' a number means to push it onto the stack.

Blank was heavily influenced by Befunge-93, except that it is one-dimensional; thus it is sometimes informally referred to as Unefunge-93.

Language overview

A program in Blank is a sequence of data, represented as [n], and instructions, represented as {c}, where n is any natural number, and c is one of the one-character instructions listed below. During execution, each data encountered is pushed on top of the stack, each instruction is executed, and when the end of the program is reached, execution continues loops over to the beginning.

The main data structure is a stack, which can hold numeric values. There is also an auxiliary stack, called the program stack. Blank programs can also access and modify their own source code, which can thus be considered a circular tape. According to the reference implementation, all values are bound to the range [- 2 ^ 31, 2 ^ 31 - 1].

Instructions

Stack operations

Symbol Description
[n]
Push number n onto the stack.
{+}
Sum top two elements: pop y, pop x, push x + y.
{-}
Subtraction: pop y, pop x, push x - y.
{*}
Multiplication: pop y, pop x, push x * y.
{/}
Integer division: pop y, pop x, push x / y.
{%}
Remainder: pop y, pop x, push the remainder of x divided by y.
{$}
Pop and discard top element.
{\}
Swap top two elements: pop y, pop x, push y, push x.
{:}
Duplicate top element: pop x, push x, push x.
{^}
Pop n, then push a copy of the nth element. The stack is one-indexed; if the top element is 0, it is popped and no element is copied.
{`}
Greater than: pop y, pop x, push 1 if x > y, 0 otherwise.
{!}
Logical not: pop x, push 1 if x = 0, 0 otherwise.
{o}
Push current stack length.

Input/output

In the reference implementation:

  • {~}, {&}, {,}, {.}, and {p} are used for interactive I/O via standard input and output;
  • {=} and {_} are used to read from an input file and write to an output file, both specified before execution.
Symbol Description
{~}
Get a character c from input, push the ASCII value of c to the stack.
{&}
Get a numeric value n from input, push n to the stack.
{,}
Pop the top element from the stack and output it as an ASCII character.
{.}
Pop the top element from the stack and output it as a numeric value.
{p}
Pop the entire stack and output it as an ASCII string.
{=}
Get the next character from input and push its ASCII value to the stack.
{_}
Pop the top element from the stack and write the corresponding ASCII character to output.
{;}
Pop the top element from the stack and output its ASCII character to the standard error stream.
{s}
Pop the entire stack as an ASCII string and execute it as a command.

Control flow

Those instructions can access the program stack. In the descriptions below, "the main stack" refers to the main stack, while "the program stack" refers to the program stack.

Symbol Description
{@}
Halt execution.
{>}
Push the location of the current cell on the program stack, then pop n from the main stack and jump n instructions to the right.
{<}
Pop a location n from the program stack, and jump to instruction n + 1. When the program stack is empty, {<} is a no-op.
{|}
Pop b from the main stack. Pop n from the main stack. If b is nonzero, then push the location of the current cell on the program stack and jump n instructions to the right.
{#}
Pop and discard the top element of the program stack.

Program modification

Symbol Description
{)}
Pop n, then create a new data cell located n cells to the right. The new cell is initially empty.
{(}
Pop n, then destroy the cell located n cells to the right.
{?}
Push the current number of cells to the stack.
{"}
Pop n, then push the value contained in the nth cell to the right of the current cell, or the value of the current cell if n is less than or equal to 0.
{'}
Pop n, pop x, then replace the content of the nth cell to the right with x. If that cell is not a data cell but an instruction cell, then the instruction is replaced with an instruction "that depends on x" - in the reference implementation it is the instruction matching the ASCII representation of x.

External resources