In this particular context, just replace '~' with 'not'.
PS. ok i guess i will have to explain - started getting slapped with -1's, probably on the premise i don't know the difference between logical and bitwise negation.
The thing is, the code in the question is broken. There is a bug in it. If you check how Brainfuck should work, it loops within [ ] braces while the current memory cell is !=0 (this is checked as pre-condition when entering [ and as optimization before returning from ]).
But instead of arguing, perhaps is easier to show with examples of the code not working. Let's take the simple program '[+]'
. Trying to tun this should just exit (because current cell is 0, it won even enter the loop). Instead if you run it in this interpreter, it goes into infinite loop.
So i'll kindly ask you to revert your -1 votes if my clarification makes sense now ;-)
Here is the interpreter slightly beautified, with fixed ~
bug and i also added the missing ,
input:
from sys import stdin, stdout
bfHelloWorld = '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.'
# http://esoteric.sange.fi/brainfuck/bf-source/prog/yapi.b
bfPiDigits = '''> +++++ (5 digits)
[<+>>>>>>>>++++++++++<<<<<<<-]>+++++[<+++++++++>-]+>>>>>>+[<<+++[>>[-<]<[>]<-]>>
[>+>]<[<]>]>[[->>>>+<<<<]>>>+++>-]<[<<<<]<<<<<<<<+[->>>>>>>>>>>>[<+[->>>>+<<<<]>
>>>>]<<<<[>>>>>[<<<<+>>>>-]<<<<<-[<<++++++++++>>-]>>>[<<[<+<<+>>>-]<[>+<-]<++<<+
>>>>>>-]<<[-]<<-<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+<<<-[>>+<<-]<]<<<<+>>>>>>>
>[-]>[<<<+>>>-]<<++++++++++<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+>[<<+<+>>>-]<<<
<+<+>>[-[-[-[-[-[-[-[-[-<->[-<+<->>]]]]]]]]]]<[+++++[<<<++++++++<++++++++>>>>-]<
<<<+<->>>>[>+<<<+++++++++<->>>-]<<<<<[>>+<<-]+<[->-<]>[>>.<<<<[+.[-]]>>-]>[>>.<<
-]>[-]>[-]>>>[>>[<<<<<<<<+>>>>>>>>-]<<-]]>>[-]<<<[-]<<<<<<<<]++++++++++.
'''
code = bfPiDigits # the code
data = [0] * 255 # data memory
cp = 0 # code pointer
dp = 0 # data pointer
while cp < len(code):
cmd = code[cp]
if cmd == '>': dp += 1
elif cmd == '<': dp -= 1
elif cmd == '+': data[dp] += 1
elif cmd == '-': data[dp] -= 1
elif cmd == '.': stdout.write(chr(data[dp]))
elif cmd == ',': data[dp] = ord(stdin.read(1))
elif cmd == '[' and not data[dp]: # skip loop if ==0
n = 0
while True:
cmd = code[cp]
if cmd == '[': n += 1
elif cmd == ']': n -= 1
if not n: break
cp += 1
elif cmd == ']' and data[dp]: # loop back if !=0
n = 0
while True:
cmd = code[cp]
if cmd == '[': n+=1
elif cmd == ']': n-=1
if not n: break
cp -= 1
cp += 1