Skip to content

Instantly share code, notes, and snippets.

@zesterer
Last active July 29, 2018 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zesterer/fefb15257b41433626572c7e88de0bee to your computer and use it in GitHub Desktop.
Save zesterer/fefb15257b41433626572c7e88de0bee to your computer and use it in GitHub Desktop.
Brainfuck Interpreter In C
// Run like: ./bf <myfile.bf>
#include<stdio.h>
main(int u,int**v){char t[1<<12]={0,},c[1<<16];int m=fread(c,1,1<<16,fopen(*++v,"r"));
char*p=t,n=0,x=0,*i=c;for(;i-c<m;){
*i==62?p++:*i==60?p--:*i==43?++*p:*i==45?--*p:*i==46?write(1,p,1):*i==44?read(0,p,1):0;
if((*i==91&&!*p)||(*i==93&&*p)){*p?n--:n++;for(;n;)*(*p?--i:++i)==91?n++:*i==93?n--:0;*p?0:i--;}i++;}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment