12 Apr 2014

Pyspeare

written by hunter | Tags: ,

Sure, most programmers can program in Java or C or C# or C++ or C-anything-else or Python, but how many can program in Shakespeare? I can, and I forked a Shakespeare-to-C translator and make a Shakespeare-to-Python translator so that everyone can neatly run the SPL code they write neatly from the confines of a Python shell. Read one for more of that. 
Esoteric programming languages are fun. Some great examples include Whitespace (where all code consists of tabs, spaces, and line breaks), Chef (where all code looks like a recipe), Omgrofl (where code looks like a bunch of lols, omgs, and rofls), and Brainfuck, where the only symbols the programmer can use are <.,>+-[ and ]. As a quick example, a Hello World program I wrote a few moments ago (which just outputs “HEY”) in Brainfuck would look like the following:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>++++++++>+++++>+++++++++++++++++++++++++<<<[>+>+>+<<<-]>[.>]
Beautiful, right? Regardless, another great example of an esoteric language is SPL, the Shakespeare Programming Language. The actual documentation does a great job of explaining the language, but the basic gist is that all the code looks right out of a Shakespeare play, and all of the commands consist of characters (the variables) manipulating the values of other characters and then ordering them to either accept input or read their value as an output. Simple enough, perhaps. The “Hello World” the creators allude to, however, is pretty complicated and looks like this. Complicated enough? Probably.
Still, I found it hilarious and knew I desperately needed to learn the language. At the very least I could submit some programs to my English teacher and get a good laugh. The problem, of course, was that I had no way of running the code. There was no compiler. A quick search revealed a SPL-to-C translator written in Python by Sam Donow but that wasn’t ideal because I don’t like running random executables output by strangers’ code I find online. Instead, I figured I was better off dissecting his code and making it a bit more useful for my purposes. The translator was already written in Python, so it made sense to tweak it so that the output was also in Python. This way I could understand everything that was going on, ensure that nothing was afoul, and even make a “compiler” a bit more useful for my purposes.
Thus I set to work. Forking Donow’s project, starting to tweak it to output Python. And, with all that, pyspeare was born. The initial release simply mimicked Sam Donow’s functionality, but subsequent tweaking implemented some missing features of the language. On my own, I added NOT conditionals and stacks, as described by the original language spec, which were missing from Sam’s project. Overall, much of the basic groundwork was laid for me, so this wasn’t a particularly time-consuming project, but it was, all the same, an excellent adventure that taught me a little bit about what goes into the making of a programming language, regardless of how silly that language happened to be.
I suppose that’s that. The Shakespeare Programming language. As usual, the basic details can be found below.
 
The Basics:
Name: pyspeare
Language: Python
Source: Here