brainfuckインタプリタ書いた。

bf.py

import sys

class bf:
  def __init__(self):
    self.i = 0
    self.ptr = [0] * 2**8
    self.action = {'>': self.inc_ptr,
                   '<': self.dec_ptr,
                   '+': self.inc_ptr_num,
                   '-': self.dec_ptr_num,
                   '.': self.output,
                   ',': self.input}

  def inc_ptr(self):
    self.i += 1

  def dec_ptr(self):
    self.i -= 1

  def inc_ptr_num(self):
    self.ptr[self.i] += 1

  def dec_ptr_num(self):
    self.ptr[self.i] -= 1

  def output(self):
    sys.stdout.write(chr(self.ptr[self.i]))

  def input(self):
    self.ptr[self.i] = ord(raw_input()[0])

  def eval(self, s):
    l = list(s)
    while l:
      a = l.pop(0)
      if a == '[':
        b = ''
        f = False
        while not f:
          c = l.pop(0)
          if c == ']':
            f = True
            while self.ptr[self.i]:
              self.eval(b)
          else:
            b += c
      else:
        if a in self.action:
          self.action[a]()

if __name__ == '__main__':
  bf().eval(file(sys.argv[1]).read())

h.bf

>+++++++++[<++++++++>-]<.
>+++++++[<++++>-]<+.
+++++++.
.
+++.
[-]>++++++++[<++++>-]<.
>+++++++++++[<+++++>-]<.
>++++++++[<+++>-]<.
+++.
------.
--------.
[-]>++++++++[<++++>-]<+.
[-]++++++++++.

実行結果

> python bf.py h.bf
Hello World!

ファッキンブレインくらいわかるよバカやろう!(←これが言いたかっただけ!)