Created
March 23, 2020 10:39
-
-
Save kuuote/e4cdffa7feb18a5cd45da5df0765ce80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! BF(fxxk) abort | |
let mem = 0z00 | |
for i in range(15) | |
let mem = mem + mem | |
endfor | |
let ip = 0 | |
let dp = 0 | |
let out = [] | |
while ip < len(a:fxxk) | |
let c = a:fxxk[ip] | |
if c == ">" | |
let dp += 1 | |
elseif c == "<" | |
let dp -= 1 | |
elseif c == "+" | |
let mem[dp] = mem[dp] + 1 | |
elseif c == "-" | |
let mem[dp] = mem[dp] - 1 | |
elseif c == "." | |
call add(out, mem[dp]) | |
elseif c == "," | |
let mem[dp] = getchar() | |
elseif c == "[" | |
if mem[dp] == 0 | |
let s = 0 | |
while v:true | |
let ip += 1 | |
let c = a:fxxk[ip] | |
if c == "[" | |
let s += 1 | |
elseif c == "]" | |
if s == 0 | |
break | |
else | |
let s -= 1 | |
endif | |
endif | |
endwhile | |
endif | |
elseif c == "]" | |
if mem[dp] != 0 | |
let s = 0 | |
while v:true | |
let ip -= 1 | |
let c = a:fxxk[ip] | |
if c == "]" | |
let s += 1 | |
elseif c == "[" | |
if s == 0 | |
break | |
else | |
let s -= 1 | |
endif | |
endif | |
endwhile | |
endif | |
endif | |
let ip += 1 | |
endwhile | |
return join(map(out, "nr2char(v:val)"), "") | |
endfunction | |
echo BF(">+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++ ++>-]<.>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]> ++++++++[<++++>-]<+.[-]++++++++++.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment