Nqubl
Nqubl is an esoteric programming language created by user:David.werecat where instructions are queued and must be explicitly executed.
Instructions
Nqubl stores each instruction that it encounters in a queue. In order to execute all instructions in the queue, the x
instruction is used. If an instruction is prefixed with i
the instruction will execute immediately, bypassing the queue. This is known as an immediate instruction.
Memory is stored in eight stacks and eight registers. Each value stored in a register or on a stack is a signed integer, where FALSE is defined as 0 and TRUE is defined as -1. Registers behave like stacks, but are not cleared when the POP operation is given. The stacks are numbered 0-1,A-F; the registers are numbered 2-9. If a stack is popped when it is empty, a zero will be used instead. The program can operate on a single current stack at a time. The current stack starts at 0, but can be changed with the instruction s
. All operations are performed on the current stack. Values can be moved from the top of the current stack to another stack using the instruction t
.
Each instruction is one letter, although some instructions have a parameter which is appended to the instruction code. When an instruction operates on the stack, it will most likely consume the values (see table below). The values are ordered so the operation is executed as TOPMOST ~operation~ UNDERTOP
. Any unrecognized instructions or whitespace are ignored.
Instruction | Immediate | Consumption | Description |
---|---|---|---|
x |
Yes | n/a | Executes all instructions in the instruction queue |
i |
Yes | n/a | Next instruction is executed immediately, bypassing the queue |
w |
Yes | n/a | Swaps the top two instructions in the instruction queue |
r |
Yes | n/a | Moves (consumes) the top instruction in the queue to the bottom |
: |
Yes | n/a | Copies (does not consume) the top instruction in the queue to the bottom |
s |
No | n/a | Changes the current stack; followed by one character specifying which stack or register to switch to |
t |
No | Yes | Moves the top element of the current stack to the top of the specified stack; followed by one character specifying which stack or register to move to |
z |
No | n/a | Pushes the size of the instruction queue onto the current stack |
o |
No | n/a | Pushes the size of the current stack onto the current stack |
g |
No | n/a | Gets a character from STDIN and pushes it onto the current stack |
u |
No | n/a | Gets a numeric value from STDIN and pushes it onto the current stack |
l |
No | n/a | Gets a single line string from STDIN and pushes it onto the current stack |
p |
No | Yes | Writes the character from the top of the current stack to STDOUT |
n |
No | Yes | Writes the numeric value from the top of the current stack to STDOUT |
e |
No | Yes | Writes all characters from the current stack to STDOUT |
c |
No | No | Copies the top element of the current stack and pushes it onto the current stack |
m |
No | No | Increments the top element of the current stack |
d |
No | No | Decrements the top element of the current stack |
+ |
No | Yes | Adds the top two elements of the current stack and pushes the result onto the current stack |
- |
No | Yes | Subtracts the top two elements of the current stack and pushes the result onto the current stack |
* |
No | Yes | Multiplies the top two elements of the current stack and pushes the result onto the current stack |
/ |
No | Yes | Divides the top two elements of the current stack and pushes the result onto the current stack |
\ |
No | Yes | Calculates the modulus of the top two elements of the current stack and pushes the result onto the current stack |
| |
No | Yes | Performs a bitwise OR on the top two elements of the current stack and pushes the result onto the current stack |
& |
No | Yes | Performs a bitwise AND on the top two elements of the current stack and pushes the result onto the current stack |
^ |
No | Yes | Performs a bitwise XOR on the top two elements of the current stack and pushes the result onto the current stack |
< |
No | Yes | Checks for a less-than condition on the top two elements of the current stack and pushes the result onto the current stack |
> |
No | Yes | Checks for a greater-than condition on the top two elements of the current stack and pushes the result onto the current stack |
= |
No | Yes | Checks if the top two elements of the current stack are equal and pushes the result onto the current stack |
! |
No | No | Performs a bitwise NOT on the top element of the current stack |
~~ |
No | n/a | Pushes the literal integer value contained between the two ~ onto the current stack |
`` |
No | n/a | Defines a comment, which is ignored by the interpreter |
"" |
No | n/a | Pushes the literal string value contained between the two " onto the current stack in in character order |
k |
No | Yes | Check the top element of the current stack and skips the next instruction if the value was zero; only skips instructions outside of the queue |
f |
No | Yes | Check the top element of the current stack and skips the next instruction if the value was zero |
[ |
Yes | n/a | NOP; although acts like a { when looking for matching # 's
|
{ |
Yes | n/a | Jumps backward to the matching #
|
] |
Yes | n/a | NOP; although acts like a } when looking for matching # 's
|
} |
Yes | n/a | Jumps forward to the matching #
|
# |
Yes | n/a | NOP; acts as a label for { or }
|
q |
No | No | Exits the program |
Examples
Cat Program
#igc~-1~=kx}ip{#
Hello, World!
"!dlrow ,olleH"ex
Fibonacci Numbers
s3~1~s0x#s2t0s3t0s0+s3t2s0t3s2nt0s0~1000000~<xik}~10~px{#
Deadfish Interpreter
# " >>"E GT3S3T0T0T0T0S0 #G~10~=KX}{# "i"=!KX}S2MS0# "d"=!KX}S2DS0# "s"=!KX}S2T3S4~0~]#S3T0S0~0~=KX}S3DS2T0S4T0S0+T4{#S4T2S0# "o"=!KX}S2NS0~10~P# S2T0T0S0 ~256~=!KX}S2~0~S0# ~-1~=!KX}S2~0~S0# [[[[[[[[{