From Esolang
Jump to navigation Jump to search

Shark is an esoteric programming language created by User:Madk in May 2019.


Shark has four registers (named A, B, C, and D), a memory map, and a control stack.

Addresses are stored on the control stack using the ^ instruction and are popped using the ~ and x instructions.

Shark's registers, memory addresses, and memory values are represented as arbitrarily large signed integers. The magnitude of integers and the breadth of the memory address space are limited only by the memory of the machine running Shark code. Memory addresses and registers are always initialized to zero at program start.

Execution begins at the first instruction in a program and continues until either the program counter/instruction pointer (PC) reaches the end of the instruction list, a jump instruction places the PC either before the first instruction or after the last one, an integer division by zero occurs, or an instruction would result in popping an empty control stack.


A hash # indicates a comment. Comments begin with the hash and end after the following newline character \n.

Characters outside of comments that are not recognized as instructions are ignored. Ignored characters are different from the nop instruction, z, which actually consumes an evaluation cycle and takes up space in program memory.


Hello, world!

# Prints "Hello world!"


# Echoes input up to the first newline '\n'

Fibonacci sequence

# Prints the first 128 numbers in the Fibonacci sequence

Collatz sequence

# Print the Collatz sequence of the input number

Instruction List

z    No operation, or "nop". Consume one cycle and take up a slot in program memory.
D    Debug helper. Dump info about the current state of the program to the console.
?    Skip the next one instruction if A is zero.
!    Skip the next one instruction if A is nonzero.
{    Jump backwards by exactly 3 instructions.
^    Add the current position of the PC to the control stack.
~    Pop the control stack and jump to the instruction after the last executed `^`.
&    Jump to the instruction after the `^` on top of the control stack, but don't pop it.
x    Pop the control stack, but don't jump anywhere.
>    Store the value of B in memory address A.
<    Set B to the value at memory address A.
w    Swap the values of B and the value at memory address A.
:    Write A to the console as a decimal number.
;    Write A to the console as a unicode code point.
n    Write a newline character `\n` to the console.
.    Wait for a line of console input and try to parse the text as an integer.
     If parsing is successful, store the value in A. Otherwise set B to 0.
,    Read one unicode code point from console input and store its value in A.
@    Swap the values of A and B.
'    Swap the values of A and C.
"    Swap the values of B and D.
$    Set B to the value of A.
0    Set A to zero.
i    Increment A.
d    Decrement A.
q    Square A.
l    Multiply A by 2.
r    Divide A by 2.
-    Negate A.
+    Set A to the sum of A and B.
*    Set A to the product of A and B.
%    Set A to the remainder of A divided by B.

External resources

Download Shark interpreter