Turns out that it took another day to get my Shakespeare compiler from "can compile Hello World properly" to "can compile most Shakespeare programs correctly." My compiler still lacks support for stacks (because who needs data structures in shakespeare, really?), multiple-word nouns in cases where using just the last word would generate any confusion (right now I cheat on multiple word names and nouns by just counting the last word..."The Ghost" is just "Ghost, " etc.), and I don't restrict variable names, though it would go against the spirit of a Shakespeare program to not restrict oneself to Shakespearean variables. Also I don't support variable declarations that go across multiple lines, but that won't be too hard to add later.
The output has gotten a bit messier since yesterday...I had to forgo my distaste for goto statements and actually implementing them, as the issue with replacing gotos with function calls is the potential for stack overflow (which my Shakespeare program did indeed run into before I put all the gotos in). Anyway, I wrote this Shakespeare compiler mostly for my own purposes, but if anyone else wants to write Shakespeare and can't find a compiler that works on the internet, here is mine: splc.py is the source for the compiler, but because I use some fairly strange input syntax, I included a bash script (called spl) which automatically compiles to Shakespeare to C, and then from C to an executable with gcc. (Also, it is worth noting that the include directory, the python script, and the bash script need to all be in the same directory for things to work).
https://dl.dropboxusercontent.com/u/34972177/SPL/spl.zip
No comments:
Post a Comment