Dienstag, 28. Juni 2011

An Ook! interpreter in Python

A recent geocache introduced me to an esoteric language named "Ook!", which was designed for Orang-Utans to communicate without arousing human suspicion.

It's pretty simple, as the language consists of only three syntax elements:
  1. Ook.
  2. Ook!
  3. Ook?
That's it. To make the language a little more powerful, elements are grouped into pairs, e.g. "Ook. Ook!" or "Ook? Ook.". So we have nine possible pairs and thus nine distinct commands, only eight of which are actually used ("Ook? Ook?" has been supplied with no deeper meaning ... maybe it's left for the Orang-Utan to express "WTF are you talking about?!").

When I felt an itch to implement an Ook! interpreter, I discovered that Ook! is all but identical to the well-known Brainfuck, since both languages have eight commands, and there exists a one-to-one mapping between them.

Furthermore, since Brainfuck is already a "minimal" language in that any command consists of one character only, I started off with the BF interpreter.

(Ok, to be totally honest, I started off implementing the Ook! interpreter, which eventually had bugs I wasn't able to track down anymore ... :) only then I realized what a stupid plan it was to begin with the Ook! part and started all over again, this time implementing the BF part first)

After finishing that, the remaining task was to implement a preprocessor which would turn an Ook! listing into a BF listing, and I was done.

If you're curious about the result, grab the code from github.

(It's my first project on github btw, and I absolutely recommend the github for mac application)

Keine Kommentare:

Kommentar veröffentlichen