annotate yn9LVhJv @ 7590:4d228c925379

<Moon_> ` gcc -x c yn9LVhJv -o bin/Something
author HackBot
date Thu, 28 Apr 2016 22:29:02 +0000
parents 0127a61014cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7589
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
1 #include <stdio.h>
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
2 #include <stdio.h>
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
3 #include <stdlib.h>
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
4 #include <string.h>
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
5
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
6
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
7 // initialize the tape with 30,000 zeroes
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
8 unsigned long long int tape[30000] = {0};
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
9 unsigned long long int registrar[3] = {0}; // R1, R2, and R3
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
10 // set the pointer to point at the left-most cell of the tape
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
11 unsigned long long int* ptr = tape;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
12
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
13
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
14
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
15 void interpret(char* input) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
16 char current_char;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
17 size_t i;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
18 size_t i2;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
19 size_t i3;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
20 size_t loop;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
21 int i4;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
22
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
23 for (i = 0; input[i] != 0; i++) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
24 current_char = input[i];
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
25 i4 = rand() % 11;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
26 if (i4 == 0) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
27 ++ptr;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
28 } else if (i4 == 1) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
29 --ptr;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
30 } else if (i4 == 2) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
31 ++*ptr;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
32 } else if (i4 == 3) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
33 --*ptr;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
34 } else if (i4 == 4) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
35 putchar(*ptr);
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
36 } else if (i4 == 5) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
37
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
38 *ptr = getchar();
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
39
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
40 } else if (i4 == 6) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
41 continue;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
42 } else if (i4 == 7 && *ptr) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
43 loop = 1;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
44 while (loop > 0) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
45 current_char = input[--i];
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
46 if (current_char == '[') {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
47 loop--;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
48 } else if (current_char == ']') {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
49 loop++;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
50 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
51 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
52 } else if (i4 == 8) { // Jump forward n spaces
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
53
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
54 for (i2 = *ptr; i2 != 0; i2--) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
55 i++;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
56 current_char = input[i];
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
57 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
58 } else if (i4 == 9) { // Jump backword n spaces
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
59 for (i2 = *ptr; i2 != 0; i2--) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
60 i--;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
61 current_char = input[i];
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
62 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
63 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
64 // More commands to come, the CIOL specs are not done
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
65 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
66 }
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
67
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
68
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
69 int main( int argc, char *argv[] ) {
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
70
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
71 interpret(argv[1]); // outputs input
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
72 return 0;
0127a61014cb <Moon_> fetch http://pastebin.com/raw/yn9LVhJv
HackBot
parents:
diff changeset
73 }