matts0613

brainfuck-parser.py

Feb 19th, 2022
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. import re,sys
  2. def f(b,r,a,i,n,f,u,c,k):
  3.  d,e,g,m=[0]*30000,0,0,''
  4.  for n in re.finditer('|'.join(r'(?P<%s>%s)'%m for m in[(j,re.escape(l))for j,l in zip('rlidoswen',[r,a,i,n,f,u,c,k,'.'])]),b):
  5.   m+=' '*g+{'r':'e+=1','l':'e-=1','i':'d[e]+=1','d':'d[e]-=1','o':'sys.stdout.write(chr(d[e])),','s':'d[e]=ord(sys.stdin.read(1))','w':'while d[e]:','e':'pass'}.get(n.lastgroup,'')+'\n';g+=n.lastgroup=='w';g-=n.lastgroup=='e'
  6.  try:exec m
  7.  except:d[e]=-1
Advertisement
Add Comment
Please, Sign In to add comment