nondescript/examples/bf.nds

107 lines
3.5 KiB
Plaintext
Raw Normal View History

2022-02-09 06:58:51 +01:00
var main = proc() {
2022-02-03 22:28:25 +01:00
// source
2022-02-05 02:45:29 +01:00
var src = ">++++++++++[<++++++++++>-]<->>>>>+++[>+++>+++<<-]<<<<+<[>[>+>+<<-]>>[-<<+>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]>>>>>>[[-]<++++++++++<->>]<-[>+>+<<-]>[<+>-]+>[[-]<->]<<<<<<<<<->>]<[>+>+<<-]>>[-<<+>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+>+<<<-]>>>[-<<<+>>>]++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<<[>>+>+<<<-]>>>[-<<<+>>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<[[-]>>>++++++++[>>++++++<<-]>[<++++++++[>++++++<-]>.<++++++++[>------<-]>[<<+>>-]]>.<<++++++++[>>------<<-]<[->>+<<]<++++++++[<++++>-]<.>+++++++[>+++++++++<-]>+++.<+++++[>+++++++++<-]>.+++++..--------.-------.++++++++++++++>>[>>>+>+<<<<-]>>>>[-<<<<+>>>>]>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<<[>>>+>+<<<<-]>>>>[-<<<<+>>>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+<<[-]]>[>+<[-]]++>>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<+<[[-]>-<]>[<<<<<<<.>>>>>>>[-]]<<<<<<<<<.>>----.---------.<<.>>----.+++..+++++++++++++.[-]<<[-]]<[>+>+<<-]>>[-<<+>>]+>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<<[>>+>+<<<-]>>>[-<<<+>>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[>+<[-]]<[>>+<<[-]]>>[<<+>>[-]]<<[[-]>++++++++[<++++>-]<.>++++++++++[>+++++++++++<-]>+.-.<<.>>++++++.------------.---.<<.>++++++[>+++<-]>.<++++++[>----<-]>++.+++++++++++..[-]<<[-]++++++++++.[-]]<[>+>+<<-]>>[-<<+>>]+++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]++++++++++. >+++++++++[>+++++++++<-]>+++.+++++++++++++.++++++++++.------.<++++++++[>>++++<<-]>>.<++++++++++.-.---------.>.<-.+++++++++++.++++++++.---------.>.<-------------.+++++++++++++.----------.>.<++++++++++++.---------------.<+++[>++++++<-]>..>.<----------.+++++++++++.>.<<+++[>------<-]>-.+++++++++++++++++.---.++++++.-------.----------.[-]>[-]<<<.[-]]<[>+>+<<-]>>[-<<+>>]++++>+<[-<->]<[[-]>>-<<]>>[[-]<<+>>]<<[[-]++++++++++.[-]<[-]>]<+<]";
2022-02-03 22:28:25 +01:00
var pos = 0;
var len = #src;
2022-02-07 05:35:07 +01:00
var chr;
2022-02-03 22:28:25 +01:00
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) {
2022-02-07 05:35:07 +01:00
chr = src[pos];
2022-02-03 22:28:25 +01:00
2022-02-07 05:35:07 +01:00
if (chr == "<")
2022-02-03 22:28:25 +01:00
if (ptr > 0)
ptr = ptr - 1
else
ptr = ptrmax
;
2022-02-07 05:35:07 +01:00
if (chr == ">")
2022-02-03 22:28:25 +01:00
if (ptr < ptrmax)
ptr = ptr + 1
else
ptr = 0
;
2022-02-07 05:35:07 +01:00
if (chr == "+")
2022-02-03 22:28:25 +01:00
if (tape[ptr] < 255)
tape[ptr] = tape[ptr] + 1
else
tape[ptr] = 0
;
2022-02-07 05:35:07 +01:00
if (chr == "-")
2022-02-03 22:28:25 +01:00
if (tape[ptr] > 0)
tape[ptr] = tape[ptr] - 1
else
tape[ptr] = 255
;
2022-02-07 05:35:07 +01:00
if (chr == ".")
write(char(tape[ptr]))
2022-02-03 22:28:25 +01:00
;
2022-02-07 05:35:07 +01:00
if (chr == ",") {
tape[ptr] = byte(input[inppos]);
2022-02-03 22:28:25 +01:00
inppos = inppos + 1;
};
2022-02-07 05:35:07 +01:00
if (chr == "[") {
2022-02-03 22:28:25 +01:00
if (tape[ptr] == 0) {
depth = depth + 1;
while (depth > 0) {
pos = pos + 1;
2022-02-07 05:35:07 +01:00
chr = src[pos];
2022-02-03 22:28:25 +01:00
depth = depth +
2022-02-07 05:35:07 +01:00
if (chr == "[")
2022-02-03 22:28:25 +01:00
1
2022-02-07 05:35:07 +01:00
else if (chr == "]")
2022-02-03 22:28:25 +01:00
-1
else
0
;
};
};
};
2022-02-07 05:35:07 +01:00
if (chr == "]") {
2022-02-03 22:28:25 +01:00
if (tape[ptr] != 0) {
depth = depth + 1;
while (depth > 0) {
pos = pos - 1;
2022-02-07 05:35:07 +01:00
chr = src[pos];
2022-02-03 22:28:25 +01:00
depth = depth +
2022-02-07 05:35:07 +01:00
if (chr == "]")
2022-02-03 22:28:25 +01:00
1
2022-02-07 05:35:07 +01:00
else if (chr == "[")
2022-02-03 22:28:25 +01:00
-1
else
0
;
};
};
};
pos = pos + 1;
};
};
2022-02-05 02:45:29 +01:00
};
main();