Repository for the Check esoteric programming language.
Using the interpreter
Run the interpreter as:
path/to/python3 path/to/src/check.py path/to/code.chk [initial stack values]
Check is a combination of a 1-D and 2-D language. Stack manipulation is done in 1-D, but control flow is done in 2-D.
Check operates on a stack. There are two data types that can be manipulated:
- Unsigned Integer
With two-dimensional semantics, control can be going in any of four directions: up, right, down, and left. The instructions
^>v< redirect the instruction pointer in their respective directions, and
# switches back to one-dimensional mode.
With one-dimensional semantics, control always proceeds forwards. When it reaches the end of the line, it proceeds to the next. It has the following instructions:
>pushes 0 to the stack.
0-9multiply the number on the stack by 10 and then add the value of their respective digits.
+adds two numbers or concatenates two arrays.
-subtracts two numbers.
_negates a number or reverses an array.
*multiplies two numbers or repeats an array a certain number of times.
$divides a number by 2.
%preforms modulo on two numbers.
oOn an integer, it outputs its character code. On an array, it flattens it and outputs it as a list of character codes. Output is without a trailing newline.
)increments an integer.
(decrements an integer.
pprints an integer or array, the way Python 3 would. Output is without a trailing newline. It does not pop the value on the stack.
<outputs a newline (equivalent to
!preforms boolean NOT. If the integer is
0or the array is empty, it pushes
1. Otherwise, it pushes
[pushes an empty array.
]wraps an element in an array.
#switches to 2-D mode, initially pointing to the left.
?switches to 2-D mode if the top stack value is 0. It does not delete the stack value.
"starts a string literal. The code points of each character in the string literal are collected in an array.
\is used as an escape character.
:duplicates the top stack element.
\swaps the top two stack elements.
@rotates the top three stack elements.
nand rotates the top
@can be seen as special cases with
;, but it rotates in the other direction.
ddeletes the top stack item.
.makes the entire stack into an array.
&unpacks all array values onto the stack.
,gets a range
[0,n)on an integer and gets the length of an array.
=gets the element of an array at an integer index.
rpops a value and stores it in the register.
Rpushes the value from the register onto the stack.
`prints everything in the stack for debugging.
Attempting to execute an invalid instruction in either mode will error. If the interpreter ever prints a stack trace, there was a bug.