a
This commit is contained in:
parent
06d579e8ac
commit
4615f188ce
50
skuska/program.c
Normal file
50
skuska/program.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// initialize the tape with 30,000 zeroes
|
||||
unsigned char tape[30000] = {0};
|
||||
|
||||
// set the pointer to point at the left-most cell of the tape
|
||||
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];
|
||||
if (current_char == '>') {
|
||||
++ptr;
|
||||
} else if (current_char == '<') {
|
||||
--ptr;
|
||||
} else if (current_char == '+') {
|
||||
++*ptr;
|
||||
} else if (current_char == '-') {
|
||||
--*ptr;
|
||||
} else if (current_char == '.' ) {
|
||||
putchar(*ptr);
|
||||
} else if (current_char == ',') {
|
||||
*ptr = getchar();
|
||||
} else if (current_char == '[') {
|
||||
continue;
|
||||
} else if (current_char == ']' && *ptr) {
|
||||
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;
|
||||
}
|
2
skuska/readme.MD
Normal file
2
skuska/readme.MD
Normal file
@ -0,0 +1,2 @@
|
||||
Riesenie inspirovane https://gist.github.com/maxcountryman/1699708
|
||||
|
Loading…
Reference in New Issue
Block a user