Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Last active August 29, 2015 13:56
Show Gist options
  • Save marcojetson/8840985 to your computer and use it in GitHub Desktop.
Save marcojetson/8840985 to your computer and use it in GitHub Desktop.
brainfuck interpreter
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *p = malloc(1024);
int l[10], j = 0, i = 0;
while (argv[1][i]) {
switch (argv[1][i++]) {
case '>':
++p;
break;
case '<':
--p;
break;
case '+':
++*p;
break;
case '-':
--*p;
break;
case '.':
putchar(*p);
break;
case ',':
*p = getchar();
break;
case '[':
l[j++] = i - 1;
break;
case ']':
j--;
if (*p) {
i = l[j];
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment