Stack Up

From Esolang
Jump to: navigation, search

Stack Up is a stack-based programming language by Nicholas Fletcher.

Stack Up uses two LIFO data stacks for storing and processing data. Each stack has no maximum depth beyond that which is imposed by hardware and holds 8-bit integers ranging 0 to 255. One stack is known as the Main Stack; the other is the Extra Stack. Except as noted, all commands effect only the Main Stack.

There are 16 commands in Stack Up. A Stack Up program is made of a sequence of commands, which are run in order. Each command is made of 3 letters; commands are case-sensitive. Each command must be on its own line; there may not be any thing else on that line. Any line without a command is treated as a comment and ignored.

The program must have the special command END on the last line. All lines after it will be ignored.

Commands

  • NEW: Pushes a 0 onto the stack.
  • CLN: Pushes a copy of the top value onto the stack.
  • DEL: Pops and deletes the top value.
  • SWP: Swaps the top two values of the stack.
  • INC: Increases the top value by 1.
  • DEC: Decreases the top value by 1.
  • ADD: Pops the top two values and pushes their sum onto the stack.
  • DIF: Pops the top two values and pushes their difference onto the stack.
  • PAS: Pops the top value of the main stack and pushes it onto the extra stack.
  • PSB: Pops the top value of the extra stack and pushes it onto the main stack.
  • INI: Has the user input an integer (0-255) and push it onto the stack.
  • INA: Has the user input an ASCII character and push its value onto the stack.
  • OUI: Pops the top value and outputs it as an integer.
  • OUA: Pops the top value and outputs the ASCII character matching it.
  • LOP: If the top value is 0, jumps foward to just after the matching STP command.
  • STP: If the top value isn't 0, jumps backward to the matching LOP command.

Note on Loops

The LOP and STP commands create matching pairs, like parentheses.

Turing-Completeness

Stack Up can be shown to be turing-complete by reduction to brainfuck.

First, use the NEW command as many times as you need; each NEW adds one cell to the tape. Then, replace the 8 commands of brainf**k, as follows:

+: INC
-: DEC
>: PAS
<: PSB
,: INA
.: OUA
[: LOP
]: STP

Put an END command at the end.

External resources

Interpeter and sample programs