StackBBQ

From Esolang
Jump to navigation Jump to search

StackBBQ is an Esolang designed by User:ZCX islptng.
BBQ stands for Binary-Based Quine(because you have to write quine to perform loops) It's a stack-based binary language, heavily inspired by bct and 1.
Yes, Binary. The program consists of 0s and 1s. And the stack is too.

Each bit is an instruction. Yes, no loops.
A 1 pushes a True to the stack, and what about 0?
A 0 first pops 3 values, first c, second b, third a.

abc
111: Push = not Pop
110: Push = Pop or Pop
101: Move bottom->top
100: Duplicate
011: Move top 3 to top
010: Swap top 2
001: Pop 1, if 0, input 8, else pop and output
000: Pop a value, if it is 1, Pop and push to the end of the program, then push it back

Interpreter

Quite buggy Python one.

prog = input("Enter program > ")
stack = []

inbuffer = []
outbuffer = []

i = -1
while i < len(prog):
	i = i + 1
	try: prog[i]
	except IndexError: break
	if prog[i] == "1":
		stack.append(1)
	elif prog[i] == "0":
		c = stack.pop()
		b = 2*stack.pop() + c
		a = 4*stack.pop() + b
		if a == 7:
			stack.append(not(stack.pop()))
		if a == 6:
			if len(stack) >= 2:
				stack.append(stack.pop() or stack.pop())
			else:
				stack.pop()
		if a == 5:
			stack.append(stack.pop(0))
		if a == 4:
			stack.append(stack[-1])
		if a == 3:
			stack.append(stack.pop(-3))
		if a == 2:
			stack.append(stack.pop(-2))
		if a == 1:
			ind = stack.pop()
			if ind == 0:
				if len(inbuffer) == 0:
					newbuffer = input() + '\n'
					for j in newbuffer:
						x = ord(i)
						temp = []
						for k in range(8):
							temp.append(x % 2)
							x = int(x/2)
						for k in range(8): inbuffer.append(temp.pop())
				stack.append(inbuffer.pop(0))
			else:
				outbuffer.append(stack.pop())
				if len(outbuffer) >= 8:
					outchar = 0
					for k in range(8):
						outchar *= 2
						outchar += outbuffer.pop(0)
					print(chr(outchar),end="")
		if a == 0:
			if stack[-1] == 1:
				prog += stack.pop(-2)
	else:
		pass
	# print("Instruction No.",i+1,"i.e.",prog[i],"\nProgram:",prog,"\nStack: ", end = "")
	for j in range(len(stack)):
		stack[j] = int(stack[j])
		# print(stack[j], end = "")
	# print("\n")
print("---------- Halts.")
while True: print(end="")