Program source
Run
// 0) { pc = pc + 1; if (pc >= program.length) { nest = 0 } else if (program[pc] == "[") { nest = nest + 1 } else if (program[pc] == "]") { nest = nest - 1 } }; return pc } function exec(program, read) { var pc = 0; var rp = 0; var output = ""; var mem = [0]; var mp = 0; var stack = []; var sp = 0; var c; var str; while (pc < program.length) { c = program[pc]; pc = pc + 1; if (c == "<") { mp = mp - 1 } else if (c == ">") { mp = mp + 1; if (mem[mp] === undefined) { mem[mp] = 0 } } else if (c == "+") { mem[mp] = mem[mp] + 1 } else if (c == "-") { mem[mp] = mem[mp] - 1 } else if (c == ",") { if (rp < read.length) { str = read[rp]; rp = rp + 1 mem[mp] = str.charCodeAt(0); } else { mem[mp] = 0 } } else if (c == ".") { output = output + String.fromCharCode(mem[mp]) } else if (c == "[") { stack[sp] = pc; sp = sp + 1; pc = skipToLoopEnd(program, pc) } else if (c == "]") { if (mem[mp] > 0) { pc = stack[sp - 1] } else { sp = sp - 1 } } }; return output } var output = exec( "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.,[+.,]", "aXY" ); document.write(output) // ]]>
Errors
Close