-
-
Save ox/302672 to your computer and use it in GitHub Desktop.
FULL Brainfuck implimentation in response to Marc-André's Gist: http://gist.github.com/302316;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Brainfuck, full implimentation, idea by Marc-André Cournoyer. this is turing complete. | |
// the bracket code was made by a friend, zli5t. my implementations were way too complex. or wrong. | |
// compile: gcc 1L.c | |
// example: | |
// ./a.out ++. | |
// expanded: | |
// incriment reg[0] by 1 | |
// incriment reg[0] by 1 | |
// print out reg[0] | |
// outputs: 2 | |
#include "stdio.h" | |
main (int argc, char *argv[]) { | |
char *arg = argv[1]; | |
char reg[300000]={}; | |
int i = 0; | |
int j; | |
while(*arg) { | |
switch(*arg) { | |
case '+': reg[i]++;break; | |
case '-': reg[i]--;break; | |
case '<': if(i!=0)i--;break; | |
case '>': if(i!=29999)i++;break; | |
case '.': printf("%i", reg[i] );break; | |
case ',': reg[i]=getchar();break; | |
case '[': if(reg[i]!=0)break;j=1;while(j!=0){arg++;if(*arg=='[')j++;if(*arg==']')j--;}break; | |
case ']': if(reg[i]==0)break;j=1;while(j!=0){arg--;if(*arg==']')j++;if(*arg=='[')j--;}break; | |
} arg++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment