这是我的interpereter的代码:
program=list(raw_input('Program: '))
array = [0 for i in range(100)]
pointer=0
prgpointer=0
run = True
while run:
try:
command = program[prgpointer]
if command == '>':
pointer += 1
if command == '<':
pointer -= 1
if command == '+':
array[pointer]=array[pointer]+1
if command == '-':
array[pointer]=array[pointer]-1
if command == '.':
print(array[pointer])
if command == '[' and array[pointer]==0:
while program[prgpointer]!=']':
prgpointer+=1
if command == ']' and array[pointer]!=0:
while program[prgpointer]!='[':
prgpointer-=1
except:
run = False
prgpointer+=1
当我运行这个程序时:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
我得到的结果
-1
-3
4
4
7
0
-2
7
10
4
-4
1
1
这个 porgram 是任何其他 bf interpereter 中的功能性“hello world”程序。即使将输出转换为 ASCII,它也不是“Hello World”。关于我的 interpereter 是否有任何重大问题可以指出?命令是否正确?