User:Feuermonster

From Esolang
Jump to: navigation, search

About

I'm a big haskell fan.

Others

Stuff:

PyBF

A simple non-wrapping BF Interpreter in Python written by me.

def bf_start():
 input_var = raw_input()
 bf_interpret(input_var)
 
def GetCell(cell):
	return abs(cell)*2 - (cell < 0)

def bf_interpret(code):
 bf_jump_right = []
 bf_jumps_right = []
 bf_jump_left = []
 for counter,chr_ in enumerate(code):
	 if chr_ == '[':
		 bf_jump_right.append(counter)
		 bf_jumps_right.append(counter)
	 if chr_ == ']':
		 bf_jump_left.append(bf_jumps_right.pop())
 #print bf_jump_right
 #print bf_jump_left
 index = 0
 index_r = -1
 index_l = -1
 Memory = [0] * 1000001
 cell = 0
 while index < len(code):
	 if code[index] == '[':
		 index_r += 1
		 if Memory[GetCell(cell)] == 0:
			 index = bf_jump_left[index_r]
			 index_r -= 1
			 #print 'Goto ',index
			 continue
		 
	 if code[index] == ']':
		 index_l += 1
		 if Memory[GetCell(cell)] != 0:
			 index = bf_jump_right[index_l]
			 index_l -= 1
			 #print 'Goto ',index
			 continue
	 if code[index] == '>':
		 cell += 1
	 if code[index] == '<':
		 cell -= 1
	 if code[index] == '+':
		 Memory[GetCell(cell)] += 1
	 if code[index] == '-':
		 Memory[GetCell(cell)] -= 1
	 if code[index] == '.':
		 print chr(int(Memory[GetCell(cell)]))
	 if code[index] == ',':
		 Memory[GetCell(cell)] = raw_input()
	 if code[index] == ':':
		 print Memory[GetCell(cell)]
         index += 1
bf_start()