7589
|
1 #include <stdio.h>
|
|
2 #include <stdio.h>
|
|
3 #include <stdlib.h>
|
|
4 #include <string.h>
|
|
5
|
|
6
|
|
7 // initialize the tape with 30,000 zeroes
|
|
8 unsigned long long int tape[30000] = {0};
|
|
9 unsigned long long int registrar[3] = {0}; // R1, R2, and R3
|
|
10 // set the pointer to point at the left-most cell of the tape
|
|
11 unsigned long long int* ptr = tape;
|
|
12
|
|
13
|
|
14
|
|
15 void interpret(char* input) {
|
|
16 char current_char;
|
|
17 size_t i;
|
|
18 size_t i2;
|
|
19 size_t i3;
|
|
20 size_t loop;
|
|
21 int i4;
|
|
22
|
|
23 for (i = 0; input[i] != 0; i++) {
|
|
24 current_char = input[i];
|
|
25 i4 = rand() % 11;
|
|
26 if (i4 == 0) {
|
|
27 ++ptr;
|
|
28 } else if (i4 == 1) {
|
|
29 --ptr;
|
|
30 } else if (i4 == 2) {
|
|
31 ++*ptr;
|
|
32 } else if (i4 == 3) {
|
|
33 --*ptr;
|
|
34 } else if (i4 == 4) {
|
|
35 putchar(*ptr);
|
|
36 } else if (i4 == 5) {
|
|
37
|
|
38 *ptr = getchar();
|
|
39
|
|
40 } else if (i4 == 6) {
|
|
41 continue;
|
|
42 } else if (i4 == 7 && *ptr) {
|
|
43 loop = 1;
|
|
44 while (loop > 0) {
|
|
45 current_char = input[--i];
|
|
46 if (current_char == '[') {
|
|
47 loop--;
|
|
48 } else if (current_char == ']') {
|
|
49 loop++;
|
|
50 }
|
|
51 }
|
|
52 } else if (i4 == 8) { // Jump forward n spaces
|
|
53
|
|
54 for (i2 = *ptr; i2 != 0; i2--) {
|
|
55 i++;
|
|
56 current_char = input[i];
|
|
57 }
|
|
58 } else if (i4 == 9) { // Jump backword n spaces
|
|
59 for (i2 = *ptr; i2 != 0; i2--) {
|
|
60 i--;
|
|
61 current_char = input[i];
|
|
62 }
|
|
63 }
|
|
64 // More commands to come, the CIOL specs are not done
|
|
65 }
|
|
66 }
|
|
67
|
|
68
|
|
69 int main( int argc, char *argv[] ) {
|
|
70
|
|
71 interpret(argv[1]); // outputs input
|
|
72 return 0;
|
|
73 } |