'Intermezzo: A brainf***-interpreter'

Posted on August 4, 2011 by phimuemue

Here's a 290-characters interpreter for the brainf*** programming language I wrote.

main(int a,char*s[]){int b[atoi(s[2])],*z=b,p;char*c=s[1],v,w;while(p=1,
*c){q('>',++z)q('<',--z)q('+',++*z)q('-',--*z)q('.',putchar(*z))q(',',*z
=getchar())if(*c=='['||*c==']'){v=*c,w=184-v;if(v<w?*z==0:*z!=0)while(p)
v<w?c++:c--,p+=*c==v?1:*c==w?-1:0;}c++;}}//gcc -D"q(a,b)"="*c-a||(b);"

It has to be compiled specifying some specialties:

gcc -D"q(a,b)"="*c-a||b;" -o pmmbf pmmbf.c

and can be invoked as follows:

./pmmbf ",[-.]" 1000

The first argument specifies the brainf***-program to be run, the second argument determines the size of the tape.