Experiments in BrainFuck

I’ve enjoyed learning about esoteric programming languages ever since I began programming. One of my favorites is BrainFuck, which feels very much like programming a turing machine directly. It has 8 commands

  • +/- increment / decrement the current data cell
  • </> move the data pointer one position left / right
  • [ if the current data cell is zero, goto the matching close brace
  • ] if the current data cell isn’t zero, goto the matching open brace
  • . print the value of the current data cell
  • , receive input into the current data cell

[] are it’s looping / conditional construct, most interesting things are built using them.

Here’s what hello world looks like

As an experiment, I tried writing a BF interpreter in Mirah (mirah-brainfuck). At this point it’s 120 some lines of code and it totally works. My next crazy idea is to write an embedded brain fuck program that works like embedded ruby. You supply a .ebf¬†file, and it gives you back a brainfuck program. Maybe I could use it to write a brainfuck web framework :p. For example, it might look like
Because this is a terrible experiment, I’ve been trying to write it in BrainFuck itself, which makes things really awkward/interesting. Because there is only one looping / conditional and it’s dependent on modifying cells on the data tape, figuring out how to compare input characters is really obtuse. But I like working with BrainFuck because it forces me to think weirdly about problems.

Comments are closed.