usaa20/sk4/program.c

47 lines
1.1 KiB
C
Raw Normal View History

2021-01-05 11:05:26 +00:00
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
2021-01-05 11:16:36 +00:00
unsigned char tape[30000] = {0};
2021-01-05 11:05:26 +00:00
unsigned char* ptr = tape;
void interpret(char* input) {
char current_char;
size_t i;
size_t loop;
for (i = 0; input[i] != 0; i++) {
current_char = input[i];
2021-01-05 11:22:02 +00:00
if (current_char == 'TUK') {//
2021-01-05 11:05:26 +00:00
++ptr;
2021-01-05 11:22:02 +00:00
} else if (current_char == 'FUK') {//
2021-01-05 11:05:26 +00:00
--ptr;
2021-01-05 11:22:02 +00:00
} else if (current_char == 'INK') {//+
2021-01-05 11:05:26 +00:00
++*ptr;
2021-01-05 11:22:02 +00:00
} else if (current_char == 'DEK') {//-
2021-01-05 11:05:26 +00:00
--*ptr;
2021-01-05 11:38:33 +00:00
} else if (current_char == 'PUK' ) {//.
2021-01-05 11:05:26 +00:00
putchar(*ptr);
2021-01-05 11:38:33 +00:00
} else if (current_char == 'KUK') {//,
2021-01-05 11:05:26 +00:00
*ptr = getchar();
2021-01-05 11:22:02 +00:00
} else if (current_char == '[') {//
2021-01-05 11:05:26 +00:00
continue;
2021-01-05 11:22:02 +00:00
} else if (current_char == ']' && *ptr) {//
2021-01-05 11:05:26 +00:00
loop = 1;
while (loop > 0) {
current_char = input[--i];
if (current_char == '[') {
loop--;
} else if (current_char == ']') {
loop++;
}
}
}
}
}
int main() {
interpret(",[.[-],]"); // outputs input
return 0;
}