7597
|
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 time_t t;
|
|
23 srand((unsigned) time(&t));
|
|
24 for (i = 0; input[i] != 0; i++) {
|
|
25 current_char = input[i];
|
|
26
|
|
27 i4 = rand() % 7;
|
|
28 if (i4 == 0) {
|
|
29 ++ptr;
|
|
30 } else if (i4 == 1) {
|
|
31 --ptr;
|
|
32 } else if (i4 == 2) {
|
|
33 ++*ptr;
|
|
34 } else if (i4 == 3) {
|
|
35 --*ptr;
|
|
36 } else if (i4 == 4) {
|
|
37 putchar(*ptr);
|
|
38 } else if (i4 == 5) {
|
|
39
|
|
40 *ptr = getchar();
|
|
41
|
|
42 } else if (i4 == 6) {
|
|
43 continue;
|
|
44 }
|
|
45 // More commands to come, the CIOL specs are not done
|
|
46 }
|
|
47 }
|
|
48
|
|
49
|
|
50 int main( int argc, char *argv[] ) {
|
|
51
|
|
52 interpret(argv[1]); // outputs input
|
|
53 return 0;
|
|
54 } |