43 lines
1.2 KiB
Text
43 lines
1.2 KiB
Text
F bf(source)
|
||
V tape = DefaultDict[Int, Int]()
|
||
V cell = 0
|
||
V ptr = 0
|
||
L ptr < source.len
|
||
S source[ptr]
|
||
‘>’
|
||
cell++
|
||
‘<’
|
||
cell--
|
||
‘+’
|
||
tape[cell]++
|
||
‘-’
|
||
tape[cell]--
|
||
‘.’
|
||
:stdout.write(Char(code' tape[cell]))
|
||
‘,’
|
||
tape[cell] = :stdin.read(1).code
|
||
‘[’
|
||
I tape[cell] == 0
|
||
V nesting_level = 0
|
||
L
|
||
S source[ptr]
|
||
‘[’
|
||
nesting_level++
|
||
‘]’
|
||
I --nesting_level == 0
|
||
L.break
|
||
ptr++
|
||
‘]’
|
||
I tape[cell] != 0
|
||
V nesting_level = 0
|
||
L
|
||
S source[ptr]
|
||
‘[’
|
||
I --nesting_level == 0
|
||
L.break
|
||
‘]’
|
||
nesting_level++
|
||
ptr--
|
||
ptr++
|
||
|
||
bf(‘++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.’)
|