Push Pop Filter
Jump to navigation
Jump to search
Push Pop Filter or PPF is an esolang devised by User:Yayimhere, to be a good & simple excersize to implement. It is inspired by Waduzitdo.
Memory
Push Pop Filter uses two stacks. One stack can be initialized, called the main stack, and another cannot. It also has two filters, one for each stack.
Syntax and commands
The program has two sections, separated by a newline:
memory program
The memory is just a sequence of symbols. That string is set as the initial main stack, with the leftmost symbol as the bottom. Then the program can have any of the following commands:
- x will pop the top of the main stack and push it to the other one
- X will pop the top of the other stack and push it to the main one.
- c will pop the top of the main stack and push it the the other one twice.
- C will pop the top of the other stack and push it to the main one twice.
- f will set the filter of the main stack to the character following the
f. - F will set the filter of the other stack to the character following the
F. - l will append the program to itself if the top of the main stack is not equal to the main stacks filter.
- L will append the program to itself if the top of the other stack is not equal to the other filter.
If anything pushed to one of the stacks is equal to the filter of the stack it is pushed to, then it will NOT be pushed.
Reference implementation
main=input().split()
fil_m=""
fil_o=""
other=[]
program=input()
i=-1
while i<len(program)-1:
i+=1
if program[i]=="x":
if main[len(main)-1] != fil_o:
other.append(main.pop(len(main)-1))
elif program[i]=="X":
if main[len(main)-1] != fil_m:
main.append(other.pop(len(other)-1))
elif program[i]=="c":
if main[len(main)-1] != fil_o:
other.append(main.pop(len(main)-1)); other.append(main.pop(len(main)-1))
elif program[i]=="C":
if main[len(main)-1] != fil_m:
main.append(other.pop(len(other)-1)); main.append(other.pop(len(other)-1))
elif program[i]=="f": fil_m=program[i+1]; i+=1
elif program[i]=="F": fil_o=program[i+1]; i+=1
elif program[i]=="l" and main[len(main)-1] != fil_m: program+=program
elif program[i]=="L" and other[len(main)-1] != fil_o: program+=program
print(main+"\n")
print(other+"\n")