Or++

From Esolang
Jump to navigation Jump to search

Or++ is a minimalist esoteric programming language created by User:TheCanon2. It is a superset of or.

Commands

Or++ has a single stack. Or++ has 6 commands.

Command Hex Action
f 0x20 0x66 Push false to the stack
t 0x20 0x74 Push true to the stack
p 0x20 0x70 Pop the top of the stack
r 0x20 0x73 Reverse the entire stack
h 0x20 0x31 Halt if the stack is empty
j 0x20 0x72 Jump to the first instruction

Or++ also accepts an input of t and f commands, which are pushed to the stack.

Examples

Quine

 f

Collatz sequence

Translated_from cyclic_tag system
 f t f f f t r p r h t f f r p r h t f f t f f t f f r p r h r p r h r p r h r p r h j

Computational class

Or++ is Turing-complete for cyclic tag system can be compiled into it.

f Append 0 to the data string.

t Append 1 to the data string.

r p r h Delete the first bit of the data string.

j repeats the loop.

Implementations

The following Python script is an interpreter.

prgm = " " # Python doesn't read spaces at the beginning of an input
init = " "
stack = []
prgm += input('>prgm ')
init += input('>i ')
for i in range(0, len(init), 2):
    j = ''.join([init[i],init[i+1]])
    if j == " f":
        stack.append(" f")
    elif j == " t":
        stack.append(" t")
    else: pass
# Executes the program
inst = 0
while inst < (len(prgm)/2):
    cmd = ''.join([prgm[2*inst], prgm[2*inst+1]])
    if cmd == " f":
        stack.append(" f")
    elif cmd == " t":
        stack.append(" t")
    elif cmd == " p":
        stack.pop()
    elif cmd == " r":
        flip = [] # reverse() doesn't work for me
        for i in range(len(stack)-1, -1, -1):
            flip.append(stack[i])
        stack = flip
    elif cmd == " h":
        if len(stack) == 0:
            break
    elif cmd == " j":
        inst = -1
    else: pass
    inst += 1
    print(stack)