Parsing commands+input in BF variant- Python 2.7.12 -


i'm modifying python brainf*ck interpreter make own variant. i'm pretty inexperienced python , need help. in code, put in # 0-9 filter , added

if command == "#": cellptr =

to list of commands. want interpreter read # , string of numbers after it. when string ends, want variable cellptr changed string. how do this? purpose of switch cell (even though isn't staying true whole point of bf) command. example code:

+>++>+++#1

add 1 cell one, 2 cell two, add 3 cell three, , jump cell one.

you need convert way general algorithm: iterate rest of code string find number until hit end of digits or end of code string. then, set cell pointer new location:

if command == "#":     num = 0     codeptr += 1     while codeptr < len(code) , code[codeptr] in '0123456789':         num = num * 10 + int(code[codeptr])         codeptr += 1     cellptr = num     codeptr -= 1 

(i've decreased codeptr one, since increment automatically again every time.)


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -