+ 1

I do not understand why this code does not work. Could someone explain it to me?

#brainf**k interpreter import sys f = open(sys.argv[1], "r") point = f.read() f.close() pointPos = 0 cell = [0] cellPos = 0 while pointPos < len(point): if point[pointPos] == ">": cellPos += 1 if len(cell)> cellPos: cell.append(0) elif point[pointPos] == "<": cellPos -= 1 if cellPos < 0: print("Error: Moved off tape!") sys.exit(0) elif point[pointPos] == "+": cell[cellPos] += 1 if cell[cellPos] >= 255: cell[cellPos] = 0 elif point[pointPos] == "-": cell[cellPos] -= 1 if cell[cellPos] <= -1: cell[cellPos] = 255 elif point[pointPos] == ".": print(chr(cell[cellPos]), end = "") elif point[pointPos] == ",": inp = input() cell[cellPos] = ord(imp[0]) elif point[pointPos] == "[": if cell[cellPos] == 0: countOpened = 0 point[pointPos] += 1 while pointPos < len(prg): if point[pointPos] == "]" and countOpened == 0: break elif point[pointPos] == "[": countOpened += 1 elif point[pointPos] == "]": countOpened -= 1 pointPos += 1 elif point[pointPos] == "]": if cell[cellPos] != 0: countOpened = 0 pointPos -= 1 while pointPos > 0: if point[pointPos] == "[" and countOpened == 0: break elif point[pointPos] == "]": countOpened += 1 elif point[pointPos] == "[": countOpened -= 1 pointPos -= 1

27th Aug 2019, 11:18 PM
Evan
0 Answers