107 lines
3.5 KiB
Plaintext
107 lines
3.5 KiB
Plaintext
var main = funct() {
|
|
// source
|
|
var src = ">++++++++++[<++++++++++>-]<->>>>>+++[>+++>+++<<-]<<<<+<[>[>+>+<<-]>>[-<<+>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]>>>>>>[[-]<++++++++++<->>]<-[>+>+<<-]>[<+>-]+>[[-]<->]<<<<<<<<<->>]<[>+>+<<-]>>[-<<+>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+>+<<<-]>>>[-<<<+>>>]++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<<[>>+>+<<<-]>>>[-<<<+>>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<[[-]>>>++++++++[>>++++++<<-]>[<++++++++[>++++++<-]>.<++++++++[>------<-]>[<<+>>-]]>.<<++++++++[>>------<<-]<[->>+<<]<++++++++[<++++>-]<.>+++++++[>+++++++++<-]>+++.<+++++[>+++++++++<-]>.+++++..--------.-------.++++++++++++++>>[>>>+>+<<<<-]>>>>[-<<<<+>>>>]>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<<[>>>+>+<<<<-]>>>>[-<<<<+>>>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+<<[-]]>[>+<[-]]++>>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<+<[[-]>-<]>[<<<<<<<.>>>>>>>[-]]<<<<<<<<<.>>----.---------.<<.>>----.+++..+++++++++++++.[-]<<[-]]<[>+>+<<-]>>[-<<+>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+>+<<<-]>>>[-<<<+>>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<[[-]>++++++++[<++++>-]<.>++++++++++[>+++++++++++<-]>+.-.<<.>>++++++.------------.---.<<.>++++++[>+++<-]>.<++++++[>----<-]>++.+++++++++++..[-]<<[-]++++++++++.[-]]<[>+>+<<-]>>[-<<+>>]+++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]++++++++++. >+++++++++[>+++++++++<-]>+++.+++++++++++++.++++++++++.------.<++++++++[>>++++<<-]>>.<++++++++++.-.---------.>.<-.+++++++++++.++++++++.---------.>.<-------------.+++++++++++++.----------.>.<++++++++++++.---------------.<+++[>++++++<-]>..>.<----------.+++++++++++.>.<<+++[>------<-]>-.+++++++++++++++++.---.++++++.-------.----------.[-]>[-]<<<.[-]]<[>+>+<<-]>>[-<<+>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]++++++++++.[-]<[-]>]<+<]";
|
|
var pos = 0;
|
|
var len = #src;
|
|
var char;
|
|
var depth = 0;
|
|
|
|
// input
|
|
var input = "";
|
|
var inppos = 0;
|
|
|
|
// tape
|
|
var tape = @[];
|
|
var ptr = 0;
|
|
var ptrmax = 30000 - 1;
|
|
|
|
var i = 0;
|
|
while (i < ptrmax) {
|
|
tape[i] = 0;
|
|
i = i + 1;
|
|
};
|
|
|
|
{ @mainloop
|
|
while (pos < len) {
|
|
char = src[pos];
|
|
|
|
if (char == "<")
|
|
if (ptr > 0)
|
|
ptr = ptr - 1
|
|
else
|
|
ptr = ptrmax
|
|
;
|
|
|
|
if (char == ">")
|
|
if (ptr < ptrmax)
|
|
ptr = ptr + 1
|
|
else
|
|
ptr = 0
|
|
;
|
|
|
|
if (char == "+")
|
|
if (tape[ptr] < 255)
|
|
tape[ptr] = tape[ptr] + 1
|
|
else
|
|
tape[ptr] = 0
|
|
;
|
|
|
|
if (char == "-")
|
|
if (tape[ptr] > 0)
|
|
tape[ptr] = tape[ptr] - 1
|
|
else
|
|
tape[ptr] = 255
|
|
;
|
|
|
|
if (char == ".")
|
|
write(chr(tape[ptr]))
|
|
;
|
|
|
|
if (char == ",") {
|
|
tape[ptr] = int(input[inppos]);
|
|
inppos = inppos + 1;
|
|
};
|
|
|
|
if (char == "[") {
|
|
if (tape[ptr] == 0) {
|
|
depth = depth + 1;
|
|
while (depth > 0) {
|
|
pos = pos + 1;
|
|
char = src[pos];
|
|
depth = depth +
|
|
if (char == "[")
|
|
1
|
|
else if (char == "]")
|
|
-1
|
|
else
|
|
0
|
|
;
|
|
};
|
|
};
|
|
};
|
|
|
|
if (char == "]") {
|
|
if (tape[ptr] != 0) {
|
|
depth = depth + 1;
|
|
while (depth > 0) {
|
|
pos = pos - 1;
|
|
char = src[pos];
|
|
depth = depth +
|
|
if (char == "]")
|
|
1
|
|
else if (char == "[")
|
|
-1
|
|
else
|
|
0
|
|
;
|
|
};
|
|
};
|
|
};
|
|
|
|
pos = pos + 1;
|
|
};
|
|
};
|
|
|
|
};
|
|
|
|
main(); |