Skip to content

Instantly share code, notes, and snippets.

@yshl
Created July 27, 2013 17:11
Show Gist options
  • Select an option

  • Save yshl/6095524 to your computer and use it in GitHub Desktop.

Select an option

Save yshl/6095524 to your computer and use it in GitHub Desktop.
Brainfuck Interpreter. bfi-0.c : ',' doesn't change memory cells at EOF. bfi-1.c : ',' returns -1 at EOF.
c['~~'];d['~~'];*p=d;n;main(i,a,q)char**a,*q;{for(read(open(a[1],0),q=c,-1);*q;n<0?q--:q++)i=*q-44,i-49?i-47?n?0:i-2?p+=i-16?i?*p-=~i?i==1:i:read(0,p,1),i==18:-1:putchar(*p):(n+=!!n)|*p||n++:n--;}
c['~~'];d['~~'];*p=d;n;main(i,a,q)char**a,*q;{for(read(open(a[1],0),q=c,-1);*q;n<0?q--:q++)i=*q-44,i-49?i-47?n?0:i-2?p+=i-16?*p-=i?~i?i==1:i:*p-getchar(),i==18:-1:putchar(*p):(n+=!!n)|*p||n++:n--;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment