esolang

Basic Stack

A stack you can see through, one register, and goto.

Nguyendinhtung2014, 2025 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello world!

The idea

Nguyendinhtung2014 made Basic Stack in 2025, after Length. The stack is transparent. Any item can be looked at, but only the top can be changed. A register holds one number and can point into the stack, and the only control flow is a test that skips the next command, and goto.

Read the story

The specification's Python interpreter reads the program until a line that says RUN, and then one line of input. It joins the lines with semicolons and cuts them apart again, so goto counts commands, not lines. The specification shows Turing completeness by turning Bitwise Cyclic Tag into Basic Stack, with the register as the left end of the data.

The machine

CommandDoes
push 5 push regPush a number or the register
popPop
+ -Pop a, pop b, push b+a or b-a
setCopy the top into the register
cond 5 cond regRun the next command only if the top equals it
condr 5 condr topThe same for the item the register points at
istopRun the next command only if the register points at the top
goto 4Go to the 4th command
in outPush the next input character, print the top as one
stopEnd

As in that interpreter, in sees only the first line of input and gives 0 after its end, out leaves the top where it is, and a command it does not know makes it loop for ever.

Example

The cat reads a character and stops at the 0 that comes after the input.
Expected: stack
Expected: 0

The cat reads a character and stops at the 0 that comes after the input. The truth machine jumps over its loop to read. On 1 it goes back to out and goto 2 for ever. The 99 bottles of beer program is 900 lines. It counts the tens of each number in the register by taking off 10 until one digit is left, so every number prints with two digits, from 99 down to 00.

Further

Ideas it shows

Stack-based

Write your own in Run Convert a program from Basic Stack

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: basic-stack.

Command line

shib run basic-stack -e 'in
cond 0
goto 6
out
goto 1
stop
RUN' --input 'cat'
shib manual basic-stack

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/basic-stack.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org