changeset 7896:bec693cb2167

<oerjan> ` mv templates/eso* src/ciol.c
author HackBot
date Fri, 06 May 2016 23:35:23 +0000
parents 3753a1bc4415
children 3827a4738fc5
files src/ciol.c templates/esolanginterptemp-ciol-
diffstat 2 files changed, 119 insertions(+), 119 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ciol.c	Fri May 06 23:35:23 2016 +0000
@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+// initialize the tape with 30,000 zeroes
+unsigned long long int tape[30000] = {0};
+unsigned long long int registrar[3] = {0}; // R1, R2, and R3
+// set the pointer to point at the left-most cell of the tape
+unsigned long long int* ptr = tape;
+
+
+
+void interpret(char* input) {
+    char current_char;
+    size_t i;
+    size_t i2;
+    size_t i3;
+    size_t loop;
+    char i4;
+
+    for (i = 0; input[i] != 0; i++) {
+        current_char = input[i];
+        if (current_char == 'p') {
+            ++ptr;
+        } else if (current_char == 'P') {
+            --ptr;
+        } else if (current_char == '+') {
+            ++*ptr;
+        } else if (current_char == '-') {
+            --*ptr;
+        } else if (current_char == 'o' ) {
+                putchar(*ptr);
+        } else if (current_char == 'i') {
+
+            *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++;
+                }
+            }
+        } else if (current_char == '/') { //push the value under the pointer to the register specified by the next value under the pointer
+            ++ptr;
+            if (*ptr > 2) {
+                --ptr;
+            } else {
+                char temp1 = *ptr;
+                --ptr;
+                registrar[temp1] = *ptr;
+            }
+        } else if (current_char == '\\') { //Same as /, except popped
+            ++ptr;
+            if (*ptr > 2) {
+                --ptr;
+            } else {
+                char temp1 = *ptr;
+                --ptr;
+                *ptr = registrar[temp1];
+            }
+        } else if (current_char == 'a') { //Add R1 to R2 and put the sum in R3
+            registrar[2] = registrar[0] + registrar[1];
+        } else if (current_char == 's') { //Subtract R1 from R2 and put the diffrence in R3
+            registrar[2] = registrar[0] - registrar[1];
+        } else if (current_char == 'd') { // Divide R1 by R2 and put the quotient in R3
+            if (registrar[1] == 0) {
+                printf("Division by zero occured, Ending!");
+                break;
+            }
+            registrar[2] = registrar[0] / registrar[1];
+        } else if (current_char == 'm') { // Multiply R1 by R2 and put the result in R3
+            registrar[2] = registrar[0] * registrar[1];
+        } else if (current_char == '*') { // Terminate
+            break;
+        } else if (current_char == 'j') { // Jump forward n spaces
+
+            for (i2 = *ptr; i2 != 0; i2--) {
+                i++;
+                current_char = input[i];
+            }
+        } else if (current_char == 'J') { // Jump backword n spaces
+            for (i2 = *ptr; i2 != 0; i2--) {
+                i--;
+                current_char = input[i];
+            }
+        } else if (current_char == 'r') { //prints out the data in the source until it hits a ;
+            i++;
+
+            i3 = i;
+            for (input[i3];input[i3] != ';';i3++){
+                putchar(input[i3]);
+                i++;
+
+            }
+
+        } else if (current_char == 'R') {
+            i++;
+
+            putchar(input[i]);
+        }
+        // More commands to come, the CIOL specs are not done
+    }
+}
+
+
+int main( int argc, char *argv[] ) {
+
+    interpret(argv[1]);  // outputs input
+    return 0;
+}
\ No newline at end of file
--- a/templates/esolanginterptemp-ciol-	Fri May 06 23:33:41 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-// initialize the tape with 30,000 zeroes
-unsigned long long int tape[30000] = {0};
-unsigned long long int registrar[3] = {0}; // R1, R2, and R3
-// set the pointer to point at the left-most cell of the tape
-unsigned long long int* ptr = tape;
-
-
-
-void interpret(char* input) {
-    char current_char;
-    size_t i;
-    size_t i2;
-    size_t i3;
-    size_t loop;
-    char i4;
-
-    for (i = 0; input[i] != 0; i++) {
-        current_char = input[i];
-        if (current_char == 'p') {
-            ++ptr;
-        } else if (current_char == 'P') {
-            --ptr;
-        } else if (current_char == '+') {
-            ++*ptr;
-        } else if (current_char == '-') {
-            --*ptr;
-        } else if (current_char == 'o' ) {
-                putchar(*ptr);
-        } else if (current_char == 'i') {
-
-            *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++;
-                }
-            }
-        } else if (current_char == '/') { //push the value under the pointer to the register specified by the next value under the pointer
-            ++ptr;
-            if (*ptr > 2) {
-                --ptr;
-            } else {
-                char temp1 = *ptr;
-                --ptr;
-                registrar[temp1] = *ptr;
-            }
-        } else if (current_char == '\\') { //Same as /, except popped
-            ++ptr;
-            if (*ptr > 2) {
-                --ptr;
-            } else {
-                char temp1 = *ptr;
-                --ptr;
-                *ptr = registrar[temp1];
-            }
-        } else if (current_char == 'a') { //Add R1 to R2 and put the sum in R3
-            registrar[2] = registrar[0] + registrar[1];
-        } else if (current_char == 's') { //Subtract R1 from R2 and put the diffrence in R3
-            registrar[2] = registrar[0] - registrar[1];
-        } else if (current_char == 'd') { // Divide R1 by R2 and put the quotient in R3
-            if (registrar[1] == 0) {
-                printf("Division by zero occured, Ending!");
-                break;
-            }
-            registrar[2] = registrar[0] / registrar[1];
-        } else if (current_char == 'm') { // Multiply R1 by R2 and put the result in R3
-            registrar[2] = registrar[0] * registrar[1];
-        } else if (current_char == '*') { // Terminate
-            break;
-        } else if (current_char == 'j') { // Jump forward n spaces
-
-            for (i2 = *ptr; i2 != 0; i2--) {
-                i++;
-                current_char = input[i];
-            }
-        } else if (current_char == 'J') { // Jump backword n spaces
-            for (i2 = *ptr; i2 != 0; i2--) {
-                i--;
-                current_char = input[i];
-            }
-        } else if (current_char == 'r') { //prints out the data in the source until it hits a ;
-            i++;
-
-            i3 = i;
-            for (input[i3];input[i3] != ';';i3++){
-                putchar(input[i3]);
-                i++;
-
-            }
-
-        } else if (current_char == 'R') {
-            i++;
-
-            putchar(input[i]);
-        }
-        // More commands to come, the CIOL specs are not done
-    }
-}
-
-
-int main( int argc, char *argv[] ) {
-
-    interpret(argv[1]);  // outputs input
-    return 0;
-}
\ No newline at end of file