This commit is contained in:
Radovan Kofira 2021-01-08 20:03:11 +01:00
parent 44522e6917
commit 3efd0f3f0b
2 changed files with 15 additions and 9 deletions

View File

@ -5,28 +5,34 @@
unsigned char tape[30000] = {0}; unsigned char tape[30000] = {0};
unsigned char* ptr = tape; unsigned char* ptr = tape;
typedef enum {
INK, DEK,
BREK, GLEK,
BF_NEXT, BF_PREV,
BF_LOOP_START, BF_LOOP_END,
} brainfuck_instruction_t;
void interpret(char* input) { void interpret(char* input) {
char current_char; char current_char;
size_t i; size_t i;
size_t loop; size_t loop;
size a;
for (i = 0; input[i] != 0; i++) { for (i = 0; input[i] != 0; i++) {
current_char = input[i]; current_char = input[i];
if (current_char == 'TUK') {// if (current_char == 'INK') {// >
++ptr; ++ptr;
} else if (current_char == 'FUK') {// } else if (current_char == 'DEK') {// <
--ptr; --ptr;
} else if (current_char == 'INK') {//+ } else if (current_char == 'BREK') {// +
++*ptr; ++*ptr;
} else if (current_char == 'DEK') {//- } else if (current_char == 'GLEK') {// -
--*ptr; --*ptr;
} else if (current_char == 'PUK' ) {// . } else if (current_char == 'PUK' ) {// .
putchar(*ptr); putchar(*ptr);
} else if (current_char == 'KUK') {// , } else if (current_char == 'KUK') {// ,
*ptr = getchar(); *ptr = getchar();
} else if (current_char == '[') {// } else if (current_char == '[') {//start loop
continue; continue;
} else if (current_char == ']' && *ptr) {// } else if (current_char == ']' && *ptr) {//stop loop
loop = 1; loop = 1;
while (loop > 0) { while (loop > 0) {
current_char = input[--i]; current_char = input[--i];

Binary file not shown.