Stackfish

From Esolang
Jump to navigation Jump to search

Stackfish is designed by islptng.

  • Stackfish is stack-based.
  • TOS:Top Of Stack.
  • If there are not any things in stack, we will push 0 to the stack.

Commands

i increment TOS
d decrement TOS
s square TOS
o output TOS
z push 0
r push a number read from stdin
n put TOS to the bottom of stack
w pop
p...q Same as bf [] but TOS instead

Examples

A+B problem

rnwrpdninqwo

Interpreter

#stackfish interpreter
code="rrnnwpdninqwo"#<-Your code here
stack=[];j=w=0;t=1
while j<len(code):
    if stack==[]:stack=[0]
    i=code[j]
    if i=="i":stack[-1]+=1
    elif i=="d":stack[-1]-=1
    elif i=="s":stack[-1]**=2
    elif i=="o":print(stack[-1])
    elif i=="z":stack.append(0)
    elif i=="w":stack.pop()
    elif i=="r":stack.append(int(input("input an integer.")))
    elif i=="n":stack=[stack[-1]]+stack[:len(stack)-1]    
    elif i=="p":
        t+=1 if stack[-1]!=0 else 0
        if t<3:w=j
    elif i=="q":
        t-=1
        if t==1 and stack[-1]!=0:j=w-1;w=0
    j+=1

MoreMathRPN esointerpreter