Skip to content

Good morrow!#

Welcome to the home of shakespearelang, a friendly interpreter for the Shakespeare Programming Language (SPL) implemented in Python and available as a package on PyPI. Aside from simply running programs, it also offers a console and debugger.

The Shakespeare Programming Language (SPL) is an esoteric language with source code that looks like William Shakespeare's plays. I take no credit for the language itself, which was designed by Karl Wiberg and Jon ├ůslund in 2001.


python -m pip install shakespearelang

Getting started#

Create a new file called first_play.spl with this text:

A New Beginning.

Hamlet, a literary/storage device.
Juliet, an orator.

                    Act I: The Only Act.

                    Scene I: The Prince's Speech.

[Enter Hamlet and Juliet]

Juliet: Thou art the sum of an amazing healthy honest noble peaceful
        fine Lord and a lovely sweet golden summer's day. Speak your

[A pause]

Juliet: Thou art the sum of thyself and a King. Speak your mind!

        Thou art the sum of an amazing healthy honest hamster and a golden
        chihuahua. Speak your mind!


In the terminal, use shakespeare run to run the play, like so:

$ shakespeare run first_play.spl

If you see the output "HI", you just successfully ran your first SPL play!


For a guide to writing SPL plays, see the original SPL documentation.

Written your play, but it's not working? shakespearelang tries to provide the most useful error messages possible, but with a language designed to be almost impossible to write, bugs are inevitable and an error message, if one is present, isn't always enough.

Activating the debugger#

Remember the stage direction [A pause] in our first_play.spl file? That special stage direction represents a breakpoint to the shakespearelang debugger. To use the debugger, run the file again with the debug command, like so:

$ shakespeare debug first_play.spl
Enter Hamlet, Juliet
Hamlet set to 72
Outputting Hamlet
Outputting character: 'H'

[A pause]

Juliet: >>Thou art the sum of thyself and a King. Speak your mind!<<

        Thou art the sum of an amazing healthy honest hamster and a golden
        chihuahua. Speak your mind!




Understanding the debugger and console#

When a play is run with the debugger, it gives more step-by-step information about the execution of a play. Here, we can see that Hamlet and Juliet entered the stage, Hamlet was set to the value 72, and then output the character 'H'.

Now, we've hit the breakpoint. The part of the text highlighted by >> and << shows us what's about to run next.

The last line (starting with >>) is a prompt, waiting for your input. This is called the "console" or the "REPL".


You can type any lines, entrances, and exits and they will be run as if they were in the current scene. You cannot use the console to start new scenes or acts, nor can you jump to another scene.

For example, you can increase Hamlet's value:

>> Juliet: Thou art the sum of thyself and a King.
Hamlet set to 73

Having the speaking character's name at the beginning of the line is optional in the console. Unattributed lines will be spoken by the last speaker.

>> Thou art a pig!
Hamlet set to -1


In addition to normal lines, the console also accepts standalone expressions, the result of which it displays. These cannot end with periods. The answers to questions are also displayed, but note that like all questions in SPL, they modify the global state!

>> Juliet: The sum of thyself and a King
>> Are you nicer than a golden chihuahua?
Setting global boolean to False

Inspecting the current state#

To see who's on stage and the values of characters and of the global boolean, type state into the console.

>> state
global boolean = False
on stage:
  Hamlet = -1 ()
  Juliet = 0 ()
off stage:

In this display, the number next to a character is the current value, while the parentheses hold the values on their stack (the rightmost values are at the top). To see a single character only, you can enter their name.

>> Hamlet
-1 ()
>> Juliet: Remember thyself!
Hamlet pushed -1
>> Hamlet
-1 (-1)


There are three special commands you can use in the console:

  • next executes the next sentence or event in the play, returning you to the interactive console afterwards.
  • continue continues running the play--it will not stop again unless it hits another breakpoint.
  • quit or exit stop execution of the play completely.

Using the console outside the debugger#

If you don't have a play yet and just want to mess around, you can open the console in the context of an empty play with the shakespeare console command, or simply shakespeare.

Other implementations#

shakespearelang is not the only implementation of SPL, though it aims to be the friendliest.

Other options: