User:Boothby

From Esolang
Jump to: navigation, search

Interpreters

BFP300: Big Python 300

A brainfuck interpreter in 300 bytes, written mostly in python. Will fail catastrophically on brackets left open, uses ints not bytes, array width 30k.

python -c "import sys;q='q';s,p=reduce(lambda(s,p),i:(s+('\n'+' '*p+'pass\
qm[p]+=1qm[p]-=1qp+=1qp-=1qm[p]=ord(sys.stdin.read(1))qsys.stdout.write(c\
hr(m[p]))qwhile m[p]:'.split(q)[i])*(i>=0),p+(i>6)-(i==0)),map(']+-><,.['\
.find,open('$1').read()),(q,0));m=[p]*30000;exec(compile(s,q,'exec'))"#BFP

PyBrain

A brainfuck interpreter in 333 bytes that doesn't resort to exec. Don't overrun the memory limit, or bad things can happen.

#PyBrain
from sys import*
def f(u,c,k):
 while(c[-2]>=k)*u:
  j,u='[]><+-,.'.find(u[0]),u[1:]
  b=(j>=0)*(1-j%2*2);c[-2]+=b*(j<2)
  while b*c[c[-1]]and j<1:f(u,c,k+1);c[-2]+=1
  b*=c[-2]==k;c[[-1,c[-1],-3][j/2-1]]+=b
  if(j==6)*b:c[c[-1]]=ord(stdin.read(1))
  if(j>6)*b:stdout.write(chr(c[c[-1]]))
f(open(argv[1]).read(),[0]*30003,0)