Monday, September 9, 2013

The real reason why I needed to write a shakespeare compiler

So, in order to validate my Shakespeare compiler, I decided to check whether I could compile all of the example programs included in the compiler I originally downloaded: I remember in that initial download, the compiler failed when compiling the two included fibonacci programs...turns out that the compiler was not wrong in failing to compile these, the programs themselves were improper Shakespeare! I certainly do not regret writing my own compiler...I have yet to test whether indeed the original compiler I downloaded does work, but I do know that mine works very well, and I may try to improve it to add some new features to the language.

So, for anyone interested in the technical reasons why the fibonacci program is not compleable, here is the example fibonacci.spl that comes with the standard Shakespeare compiler:

By Peter Nillius 2001-08-31
nillius at nada dot kth dot se

Fibonacci's numbers.

Romeo, a lover with an accumulative memory.
Juliet, a beautiful but domineering woman.
Ulysses, a spaceman.


                    Act I: A Minimalistic Play.

                    Scene I: Juliet Sets Things Straight.

[Enter Romeo and Juliet]

Juliet:
 You are nothing. Remember yourself.
 You are the difference between nothing and a pig.
 Open your heart!

[Exit Romeo]

[Enter Ulysses]

Juliet:
 You are the twice the square of the product of an stinking
 goat and a fat pig. Speak your mind!


[Exit Ulysses]

[Enter Romeo]

Romeo:
 You are me.

Juliet:
 Recall your inner most fears. You are the sum of me and thyself. 
 Are you better than nothing?

Romeo:
 If not, we shall proceed to scene IV.

Juliet:
 Open your heart! Remember me.
 
[Exit Romeo]


[Enter Ulysses]

Juliet:
 Speak thy mind! 

Ulysses:
 We must return to Scene II.


[Exeunt]
First I would like to note that all is not for nought - trying to compile this alerted me to an issue in my compiler: it now has support for multi-line titles (This has yet to be commited to git...but it will probably eventually)
 But the issues are:
 1) The declarations cannot parse correctly - neither "lover" nor "spaceman" are acceptable nouns in the included wordlists, but I added them after seeing this.
 2) The real reason why no Shakespeare compiler could correctly compile this code: There are lines saying "we shall proceed to scene IV" and "We must return to Scene II" - with those not familiar with Shakespeare syntax, these statements mean "goto scene IV" and "goto scene II" - but scenes are just lables, declared with lines like the "Scene I: Juliet Sets Things Straight." in the above program - but there are no scenes II and IV declared, so these goto statements are attempting to jump to labels that do not exist!

So, there are many, many things wrong with the examples in the default shakespeare compiler...I do not know now whether that compiler does work on the other examples, but I do know that mine does.

This ends my digression, both from the main point of this blog and from the homework I am supposed to be doing.

No comments:

Post a Comment