#The Infamous [Shakespeare Programming Language](http://esolangs.org/wiki/Shakespeare)

Shakespeare Programming Language was created in 2001 by two Swedish students, Karl Hasselström and Jon Åslund, and it combines, as the [authors proclaim](http://shakespearelang.sourceforge.net/report/shakespeare/#SECTION00030000000000000000), 

> the expressiveness of BASIC with the user-friendliness of assembly language. 

<!-- language-all: lang-spl -->


**Factoid:**

Shakespeare's code resembles, as one would expect, a Shakespeare play, where the variables are characters on the play and their value changes as they are "insulted" or praised".

**Length 1 snippet:**
 
    I
 
Shakespeare's code is divided in Acts, and the acts are themselves divided in Scenes, for "jump-to" causalities. Defining an Act as `Act I` means that it will be the first piece of the code to be run, per example - but not only.


**Length 2 snippet:**
 
    as

Used in a comparative between two "characters".


**Length 3 snippet:**

    day

By now, you may be getting the feeling that SPL is very verbose. And weird. And you've seen nothing yet. `day`, in SPL, is 1. All "positive" and "neutral" nouns are considered as `1`, as well as all "negative" ones are `-1`.


**Length 4 snippet:**

    rich

What is `rich`? An adjective. In SPL, adjectives make the value of the noun they're attached to multiply by two. See implementation on snippet 14.


**Length 5 snippet:**

    Act I

Implementation of the first snippet. All acts may be given a title, such as `Act I: Hamlet must die!`, since everything after the Roman numeral is ignored by the parser.


**Length 6 snippet:**

    better

Every language has conditions, and SPL is no exception. Except, since this is a language with a lengthy syntax (and did I mentioned it to be weird?), its conditional statements are going to be long. Having Ophelia ask Juliet `Am I better than you?` is like having `if (Ophelia > Juliet)` on most "normal" languages. And, of course, you can ask the other way around: `Am I not better than you?` is the equivalent of `if (Ophelia < Juliet)`. And you can already guess how the `=` is translated to SPL: `as good as` - usage of code snippet 2.

However, `good/better` is not the only way to make comparisons in this shakesperian language, you can use any adjective. The same principle of snippet 3 applies here as well, with "positive" adjectives having the value `>`, while "negative" ones mean `<`. 


**Length 7 snippet:**

    Juliet:

This is the invocation of a variable; after this, his/her instructions/declarations/whatever will follow. 

A limitation of SPL is that it has a limited number of variables: Romeo, Juliet, Hamlet, Ophelia, MacBeth and so on are a few examples of "characters" that will appear on a Shakesperian program.


**Length 8 snippet:**

    [Exeunt]

`[Exeunt]` is placed when all "characters" leave the "stage". Hopefully I can elaborate a bit more later on about the interaction between characters. Generally is the last instruction of any SPL program, although `[Exeunt]` isn't specifically the terminal "character" of the language. For another example, see snippet 27.


**Length 9 snippet:**

    as bad as
 
Nine characters just to represent a mere `=` - using snippet 2. Have I mentioned that SPL is weird? See snippet 30 for examples.
(and yes, there's more than one way to output it)


**Length 10 snippet:**

    difference

A fancy way of representing `-`, a subtraction. You can have math operations on SPL, even though you'll probably need a full day to get it right.


**Factoid**
_(since I managed somehow to reach ten snippets of code, let's take a bit of a break and have another factoid about SPL)_

If you want to run your shakesperian code in all its glory, there's [this site](https://shakespearelang.org/) - I'm still testing it, since I discovered it not even five minutes ago. There's also a way to translate it to C using [a translator](http://shakespearelang.sourceforge.net/report/shakespeare/#SECTION00070000000000000000).


**Length 11 snippet:**

    [Exit Romeo]

Yes! At last I can talk about the interaction between characters! In order to have its value changed or to interact with others, a "character" must be on stage - entering with `[Enter Romeo]`. If a character is addressed to but is not present, there's a runtime error and the program stops. Because, in SPL, the value of the variables is set by the amount of names they're praised with - or insulted with - by the other characters on stage. I feel that I should put an example to clear some confusion my lame explanation may create, but perhaps it's best to delay that a few snippets.



**Length 12 snippet:**

    Remember me.

SPL is pretty "basic", alright - but it has stacks! When, per instance, Romeo tells Juliet to "remember him", he's actually telling his loved one to push the Romeo's value into her stack. Popping the value is done with `Recall your happy childhood!`, or `Recall your love for me`, or basically any sentence that begins with `Recall` - the rest is just artistic drivel, like snippet 22.



**Length 13 snippet**

    Let us return

The Shakesperian way of having a `goto`. And this is where the Acts and Scenes come in handy. If Romeo tells Juliet `we shall return to Act II` (yes, again, there are multiple ways of write it), the program will jump to that specific part of the code. It's also seen alongside conditional statements.



**Length 14 snippet**

    my little pony

Yes, it was a series back in the 80s. Here, it's `2*1`. Why? Because a `pony` is a (somewhat) positive noun and `little` is an adjective. So, remembering snippets 3 and 4, we have `little = "2 *"` and `pony = "1"`.



**Length 15 snippet**

    Speak thy mind!

In a SPL program, you'll see this (or `Speak your mind!`, which is the same) *a lot*. This basically outputs the value of each "character" in digit, letter or anything else, depending on the character set being used by your computer. There's also `Open your mind.` that does almost the same thing, albeit only outputting in numeric form.



**Length 16 snippet**

    You are nothing!

When someone tells you this in real life, you'll feel depressed. When Ophelia tells this to Hamlet in Shakespearian programming, Hamlet feels worthless. What does this mean? That `Hamlet = 0`.



**Length 17 snippet**

    Ophelia, a wench.

In a screenplay, before the actual play starts, the characters must be presented. In most programming languages, the variables must also be declared before use. Seeing that SPL is a programming language that resembles a screenplay, this is how you declare its variables, by stating which are the ones appearing during the program.

But what does "a wench" mean? Does it mean that it's a specific (and cool) data type name? Well... I hate to disappoint you, but it means nothing: everything after the comma is disregarded by the parser, meaning you can put there the most outrageous drivel you can think of.



**Length 18 snippet**

    lying sorry coward

`-4` for all earthly creatures. Why? Because `2*2*(-1) = -4`.



**Length 19 snippet**

    Romeo:
     Remember me.

At last!!! I can finally output a full correct syntax instruction (albeit a short one)! This is how you use snippet 12: firstly you declare who's talking, then on the next line you write the "dialogue". Normally, only two "characters" are on stage, to avoid making the parser sad and confused. When you need another "character", you take one from the stage and replace him by the new one.



**Length 20 snippet**

    cube of thy codpiece

I wanted to elaborate a bit more for this one, but, truth be told, the things I come up with are still too short for this snippet length. And, so, I bring you this, which ends up being `-1` - because (-1)<sup>3</sup> = -1 (and `codpiece` is a "negative" noun, since they're uncomfortable and all). SPL understands a few more elaborate arithmetic operations as *some* exponentiation and square roots.



**Factoid** _(yet another one, since we've reached another milestone)_

The "Hello World Program" in Shakesperian has 89 lines and more than 2400 characters long, [as seen here](http://shakespearelang.sourceforge.net/report/shakespeare/#SECTION00091000000000000000).



**Length 21 snippet**

    Listen to your heart.

In snippet 15 you outputted something; here, you input a number to the program. If you want to input a character, you'll use `Open your mind.` instead. And, needless to say, this value will be stored in the "character" being spoken to.



**Length 22 snippet**

    Recall your childhood!

Popping an integer from a stack is done with this, as explained on snippet 12. When, per instance, Ophelia tells Hamlet the aforementioned sentence, it causes Hamlet to take an integer from his stack and assume that value.

Of course that, as long as the word `recall` is starting the sentence, you can fill in the rest with pretty much anything your creative shakesperian mind desires.


**Length 23 snippet**

    Are you better than me?

Implementation of snippet 6. When a "character" makes a question like this to another, what he/she is doing is equivalent to `if (x > y)` on more common programming languages. The follow-up of this instruction must be delayed until I have more characters available.



**Length 24 snippet**

    [Enter Romeo and Juliet]

Yes, "characters" may enter in pairs. It's not required to have one "character" entering the stage, being followed by another. 



**Length 25 snippet**

    remainder of the quotient

25 characters just to write a `%`. 25 characters to have the remainder of a division. And to use it? Well, that's even bigger.



**Length 26 snippet**

    Let us return to scene II.

Here it is, a `goto` in SPL, which works as one would expect in a programming language. A thing is: you can jump between scenes in the same act, and between acts; but you cannot jump between scenes in different acts.



**Length 27 snippet**

    [Exeunt Ophelia and Hamlet]

When more than one "character" leave the stage, instead of `Exit`, and keeping in tradition with SPL's theatrical nature, the latin word "Exeunt" is used. Sometimes it can be replaced just by snippet 8.



**Length 28 snippet**

    Scene I: Ophelia's flattery.

Declaring a Scene. As you can already expect if you've been coping with me, the important bit is the `Scene I`, the rest is artistic fluff.

There have been some compilers made (like [this one that compiles from SPL to C, written in Python](https://github.com/drsam94/Spl)) that instead refer to the text after the numbering of the Act/Scene. While more logical (after all, during a play, having the characters saying lines such as "let us return to Act I" may be deemed silly), I'm sticking to the original way.



**Length 29 snippet**

    You pretty little warm thing!

Yes, yet another constant (since we need *way more* characters to have arithmetic operations). This one is equal to `8`, because `2*2*2*1 = 8`.



**Length 30 snippet**

    You are as cowardly as Hamlet!

Saying this to, per instance, Romeo, means that `Romeo = Hamlet`. Like snippet 9.



**Factoid** _(yes, another landmark reached!)_

This language was created for an assignment in a Syntax Analysis course - thus, no SPL compiler was created by the authors. More: it seems SPL's authors have severed their ties with their creation, since nothing appears to have been modified in the language since 2001...



**Length 31 snippet**

    Am I as horrid as a flirt-gill?

Yes, I know, it's somewhat repeating snippet 23, although, here, we're comparing the "character" who speaks with a "flirt-gill" (of, if you prefer, `if (Ophelia == -1)`). The thing is...



**Length 32 snippet**

    If so, let us return to scene I.
	
... now I can introduce the `then` of SPL, and the conditional jump-to, and the Shakesperian way of implementing loops. You can, per instance, make Romeo assume the value `0`, increment his value while doing some other task and stop when he reaches 10, proceeding with the program afterwards.



**Length 33 snippet**

	If not, let us return to scene I.

Just a reminder that , instead, we can instead proceed forward to another scene if the condition we tested for *is false*.



**Length 34 snippet**

    Open your mind! Remember yourself.

Two instructions in a row, yippie! The first one reads a character, the second one pushes it into the other character's memory stack.

	

**Length 35 snippet**

    Act I: Death!
    
    Scene I: Oh, shit.

The proper way of declaring an Act and a Scene. Add artistic mush tastefully.



**Length 36 snippet**

    Thou art as sweet as a summer's day!

Another way of saying that the "character" being spoken to will receive the value `1` - because summer's days are nice and pleasant.
	


**Length 37 snippet**

    Art thou more cunning than the Ghost?

Ophelia asking this question to Hamlet means, translating this to a less readable programming language, `if (Hamlet > the Ghost)`. It's snippet 23 all over again, yeah - but it goes to show you that it's not required to ask the "characters" if they are better than each other: any other question will work too.



**Length 38 snippet**

    [Enter the Ghost, Romeo and the Ghost]

Yes, I'm calling a "character" twice - because I wanted to have the program give me an error. Calling a "character" that's already on stage, or telling one that's absent to exit, will cause great grief to the parser/compiler.



**Length 39 snippet**

    the sum of a fat lazy pig and yourself!

The full instruction is more better looking that this, I'll give you that, but... here's our first arithmetic operation! What does it all mean, actually? Well, `pig` is a dirty animal (albeit tasty), so it's equivalent to `-1`, has two adjectives, meaning `fat lazy pig` equals `2*2*(-1) = -4`. But what about `yourself`? It's a reflexive pronoum, not a name nor an adjective. Well, remember that SPL is based on dialogues between "characters"; thus, `yourself` refers to the other "character" on stage. So, we arrive at the end and we discover that "the sum of a fat lazy pig and yourself" is, in fact, `-4 + x`.



**Length 40 snippet**

    the sum of a squirrel and a white horse.

Yes, another sum, but this one is simpler than snippet 39. This is merely `1 + 2` - `3`, if my math is correct.



**Factoid** _(still with me after these forty snippets of artistic fluff? You deserve a prize.)_

SPL, in its version 1.2.1, can be downloaded [here](http://shakespearelang.sf.net/download/spl-1.2.1.tar.gz).



**Length 41 snippet**

    Juliet:
     Speak thy mind!

    [Exit Romeo]

Sometimes, "characters" are only called on stage to have their value changed - which, on a real play, would be something quite bizarre. Anyway, here, Juliet makes her beloved Romeo print his stored value, after which he exits the stage.



**Length 42 snippet**

    Speak YOUR mind! You are as bad as Hamlet!

Again two instructions in one line (we can have multiple, but the snippet length doesn't allow it yet); here we have a "character" telling another to output its value and assume whichever value Hamlet has. Confusing? Mayhap.



**Length 43 snippet**

    Am I as horrid as a half-witted flirt-gill?

Juliet asking this doesn't mean she has low-esteem (although it might in real-life); it's simply another `if`, like snippets 23 and 37. Oh, I almost forgot: this translates to `if (Juliet == -2)`.



**Length 44 snippet**

    You are as evil as the square root of Romeo!

Yes, square roots are evil, didn't you know? Anyway, this instruction is straightforward enough to understand what it does: attributes the "character" being spoken to the value of the square root of the value stored in Romeo.



**Length 45 snippet**

    Hamlet:
     Art thou more cunning than the Ghost?

Snippet 37 properly written with the character who's speaking the line.



**Length 46 snippet**

    the product of a rural town and my rich purse.

Okay... anyway, SPL may be the only language in the world that allows you to multiply towns with purses. This means `(2*1)*(2*1)` which, if I'm not very mistaken, is equal to `4`.



**Length 47 snippet**

    Romeo:
     Speak your mind.
    
    Juliet:
     Speak YOUR mind!

I'll give you that: it may be one of the most bizarre dialogues in history. But it's what you get when you choose a weird language to showcase. Romeo and Juliet are telling each other, in short, to output their values.



**Length 48 snippet** 

    You lying fatherless useless half-witted coward!

Translating it directly, `2*2*2*2*(-1)`. `-16`, right?



**Length 49 snippet**

    Scene V: Closure.

    Hamlet:
     Speak your mind!
    
    [Exeunt]

An example of how to terminate a program in SPL. You can declare a scene specifically for it (although it's not required), then Hamlet asks another "character" to output their value, then they all exit the stage. And yes, it's required for all of them to get off the stage.



**Length 50 snippet**

    Othello, a young squire.
    Lady Macbeth, an old fart.

More "character" presentation, before the proper instructions. As always, the only thing that matters to the compiler is `Othello` and `Lady Macbeth`, so the rest of the line is up for grabs... 

One more thing: the "characters" don't have to be related to each other in order to appear in a SPL program - so you can have Romeo, Othello and Hamlet on the same play.



**Factoid** _(half-a-century of these things? Phew! After this I think I'm going to loathe William Shakespeare...)_

The SPL to C translator, mentioned a while ago and developed by the SPL creators, was based on [Flex](http://flex.sourceforge.net/) and [Bison](http://www.gnu.org/software/bison/).



**Length 51 snippet**

    Othello:
     Recall your great dreams. Speak your mind!

_(So sick of Romeo, Juliet and Hamlet... let's bring in Othello, for a change!)_

`Recall`, as you can guess, is the key here. The "character" Othello is addressing will take a value from his/her stack, assume that value and, afterwards, will output it.


**Length 52 snippet**

    Thou art as pretty as the sum of thyself and my dog!

Another sum. Yawn. Assuming this one is addressed to Hamlet, means that `Hamlet = Hamlet + 1`. Or `Hamlet += 1`. Or `Hamlet++`.



**Length 53 snippet**

    Romeo:
     You are as vile as the sum of me and yourself!

Ah, yes, something I forgot to mention before: the speaking "characters" can mention themselves on their own lines. 



**Length 54 snippet**

    Juliet:
     Is the sum of Romeo and me as good as nothing?

Another example of the previous snippet, included in a condition. So what we have here is `if (Romeo + Juliet == 0)`.



**Length 55 snippet**

    Juliet:
     You are as lovely as the sweetest reddest rose.

So, here, Juliet is praising the "character" she's speaking to (let's assume it's Romeo, for Shakespeare's sake), declaring that he/she is 4. Yes, another assignation of values.