From Esolang
Jump to navigation Jump to search

Ral is a stack-based random-access esoteric language created by Code Golf and Coding Challenges user Herman-L.


Ral has a stack and a random-access memory. The stack is used as working memory by all commands. The memory is initially filled with zeroes. Popping from the stack when empty returns zero. Similar to brainfuck, all opcodes are single bytes. The opcodes in Ral are:

Opcode Pseudocode Description
0 Push 0 Push 0 to the stack
1 Push 1 Push 1 to the stack
+ Pop A Pop B Push A+B Integer addition
- Pop A Pop B Push A-B Integer subtraction
: Pop A Push A Push A Duplicate the top of the stack
/ Pop A Pop B Push A Push B Swap the top two values on the stack
* Pop A Push Memory[A] Load a value from memory
= Pop A Pop B Memory[A]=B Store a value to memory
, Input A Push A Input a value; zero if end of input is reached
. Pop A Output A Output a value
? Pop A Pop B If B>0 Goto A Jump to A if B is positive
_ Does nothing

The jump opcode jumps to the A-th opcode in the program (zero-indexed), ignoring comments. The _ opcode can be used to pad jump destinations, as it does nothing but does count as an opcode. For example, jumping to index 4 in the following program jumps to the +:

0 foo 1__+ bar :

Jumping to negative indexes results in jumping to the start of the program. Jumping to indexes larger than the number of opcodes jumps to the end of the program, terminating it.

Sample Code

Add two values


Cat program

Copies all input to the output until end of file is reached.


Hello, world!

Outputs the values 72 101 108 108 111 44 32 87 111 114 108 100 33, the code points of Hello, World!.



A program that prints itself.


Implementation notes

  • Values are integers and can be arbitrarily large.
  • The memory should support negative and extremly large indexes.
  • Input and output format is intentionally left undefined. An interpreter may, for example, take input as bytes, UTF-8 encoded characters, a list of integers, or in any other format.