Daily Archives: 8/18/2006

Pathological Programming in SNUSP

I have a pretty keen interest in programming languages, and sometimes this leads me to esoteric or even perverse extremes. For instance, I had fun with brainfuck for a while, even writing a compiler for the language that fit in my .signature file:

#define P(C,X)case C:printf(#X);break; /* bftoc.c by markv@pixar.com */
main(){int c;printf("char a[9999];main(){char*p=a;");while((c=getchar())>=0)
{switch(c){P(62,p++;)P(60,p--;)P(43,++*p;)P(45,--*p;)P(46,putchar(*p);)P(44,
*p=getchar();)P(91,while(*p){)P(93,});}}printf("exit(0);}");exit(0);}

For an interesting complication of this idea, surf on over to the Good Math, Bad Math blog and check out
Pathological Programming in SNUSP. It’s… well, I think it’s pretty cool.

[tags]Brainfuck,SNUSP,Good Math,Esoteric Programming Languages[/tags]

Addendum: I coded up a SNUSP interpreter in about an hour, which draws the program on the screen and animates the position of the program counter using curses. It’s kind of interesting to watch programs execute, particularly the Ackerman’s function, which has the unique attribute of somtimes executing loops in a clockwise direction, and other times executing them in the reverse direction.