我看似功能正常的 BF interpereter 不能 运行 标准 BF 程序

My seemingly functional BF interpereter cannot run standard BF programs

这是我的解释者的代码:

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

此程序是任何其他 bf 解释器中的功能性 'hello world' 程序。即使输出转换为 ASCII,它也不是 'Hello World' 关于我的解释者,有什么可以指出的主要问题吗? 命令是否正确?

  1. 要在您的数据指针处打印 char 值,您需要 sys.stdout.write(chr(array[pointer])),否则您将只打印数字——毕竟所有数字都在您的列表中。

  2. 语言规范说 [] 表示跳转到 匹配的 括号。您正在跳转到 next/previous 括号。