This document serves only the purpose of introducing a new
programmer to the fantastic world of Shakespeare Programming Language.
For more information regarding the language you are highly recommended
to visit the
home page of SPL .
Here a brief explanation of the basic and fundamental constructs
of the language is given.
The Shakespeare Programming Language is different from the
ordinary languages. It has got a wonderful syntax. The programs
resemble the Shakespearian plays. The whole program is arranged as
dialogues between the different characters in the play. It
is divided into acts, which are further divided into scenes. Each
scene consists of different lines, which may be the statements of
different characters on the stage.
Every program starts with a title. It is used to just give an
idea about the program. Everything up until the first period is the
Be careful to insert the title, otherwise the compiler takes
the first line it sees as the title of the program.
Next, we can introduce the characters participating in the
play. They just serve the purpose of variable declaration. Every
character used in the play has to be declared, otherwise the
compiler will complain. We can use any valid Shakespearian character.
Syntax := name, description.
Romeo, an extremely faithful lover.
Here the compiler treats 'Romeo' as a variable capable of holding
an integer value.
Acts and Scenes
Play is divided into Acts, which are further divided into
Syntax := ACT roman numeral : description.
Syntax := SCENE roman numeral : description.
Act I : Romeo and Juliet express their feelings.
Scene III: Romeo's Love.
Enter Exit and Exeunt
Characters can enter the stage and also exit from the stage. One character
present on the stage can talk to the second person on the
stage. New characters can enter the stage using 'Enter' construct.
Characters present on the stage can leave by using 'Exit' construct.
The plural of 'Exit' is 'Exeunt'. Exeunt used alone causes everyone
on the stage to leave.
Syntax := [ENTER character]
Syntax := [ENTER characterlist]
Syntax := [EXIT character]
Syntax := [EXEUNT characterlist]
Syntax := [EXEUNT]
[Enter Romeo and Juliet]
[Exeunt Romeo and Juliet]
A 'healthy conversation' is possible with the presence of two
characters on the stage, because the use of "You" won't be ambiguous.
Also the compiler complains when the presence of more than two
characters are detected.
Scenes are further divided into lines. Characters on stage
can talk to each other.
Syntax := character : sentences.
Different types of sentences are explained below.
above syntax, it is assumed that the sentence is made by that
particular character, and the use of terms like "You" denotes the
second person on the stage.
A noun is a constant. It has got a value = 1, if the noun is
nice, for example "flower" or if it is a neutral noun, for example
"tree". If the noun is dirty like "pig" it has a value = -1.
When a noun is prefixed with an adjective, it has the effect
of multiplying by two. For example, a "beautiful flower" has a value
= 2 (2 * 1). Another adjective added, again multiplied by two and so on.
For example, "fat dirty pig" has a value = (2 * 2 * -1).
Binary and Unary Operators
SPL supports all the basic binary and unary operators. For
example, we can write "the sum of X and Y" (where X and Y are
integers) for addition.
Similar syntax are shown below
"the difference between" for subtraction.
"the product of" for multiplication.
"the quotient between" for division (integer).
"the remainder of the quotient between" for remainder in division.
"the sum of" for addition.
Similarly there are Unary Operators also.
"the cube of" for obtaining the cube.
"the factorial of" for obtaining the factorial.
"the square of" for obtaining the square.
"the square root of" for obtaining the integer square root. (rounded of)
"twice" for obtaining the multiple of two.
"the sum of the difference between a big mighty proud kingdom and a horse and your golden hair."
The above example can be translated as "the sum of the
difference between 8 and 1 and 2".
Which is equivalent to 7+2 = 9.
Assignment Of Values
The above constants can be assigned to the character on the
stage. For example consider the statement
"You stupid fatherless coward!"
The compiler takes the statement to assign the value = -4 to
the character being spoken to. This statement has the same effect
of assigning second person on stage = -4'.
Another type of assignment is using the construct "as
adjective as". For example,
"You are as good as a beautiful red rose."
The above example causes the compiler to assign the value = 4
to the character being spoken to.
In the same manner any assignment can be made possible using
the constants, binary and unary operators and the assignment
construct. For example,
"You are as prompt as the difference between the square of thyself and your golden hair."
In the above example, "square of thyself" causes the compiler
to take the square of the value of the character being spoken to.
"Open your heart." It causes the character being spoken to, to
output his or her value in numerical form.
"Speak your mind." It causes the character being spoken to, to
output his or her value in character form.
To read a number use "Listen to your heart." To read a
character use "Open your mind."
The value will be assigned to the character being spoken to.
A Small Example
With our current knowledge, let us write a small program, which
reads two integer values and produces their sum as the result.
A simple program to add two values.
Romeo, A character to store the sum.
Juliet, An admirer who helps to calculate the sum.
Act I: A simple play.
Scene I: Juliet's conversation with Romeo.
[Enter Romeo and Juliet]
Juliet: Listen to your heart!
Romeo: You are as beautiful as a sweet red rose.
Listen to your heart.
Juliet: You are as brave as the sum of me and thyself.
Open your heart!
The program starts with a Title. It is followed by the
introduction of characters participating in the play. Hence in the
program, we can deal with two characters - Romeo and Juliet.
The two characters are initialized to zero by the compiler.
The play consists of a single act and a single play. In the
scene we take the two characters on the stage. First Juliet
speaks, to read the first integer value. It is stored in Romeo.
Then it is Romeo's turn. He starts with a praise which stores
the value 4 in Juliet (simply, to add beauty to the program).
Then the second value is read and stored in Juliet. Juliet
ends the conversation by storing the sum of first and second
value in Romeo. It is displayed.
The Scenes and Acts in the play act as labels, so that a
jump to a scene or act is possible. It is not possible to jump
to a scene in a different act. The general syntax is
"Let us return to scene I." Instead of "Let us", "We shall" or
"We must" can also be used. Also "return" can be replaced by
In the conditional statements, first someone raises a
question. This involves some sort of comparisons, which may
produce a true or false value. Depending on that, later, a
conditional statement is made with the help of "If so, " or
"If not, ". For example,
Juliet: Am I better than you?
Hamlet: If so, let us proceed to scene II.
Comparisons are made as "is X as good
as Y". It tests for equality. Similarly by using any positive
comparative, greater than is made possible. Negative comparative
gives less than.
Syntax := "is X as adjective as Y" for equality.
Other examples include
"Is X better than Y." for greater than.
All the characters in the play are really stacks, capable of
storing more values. The basic operations such as push and pop are
Push operation is possible by the statement "Remember me".
Lady Macbeth: Remember me.
This causes whoever Lady Macbeth is speaking to, to push
the value of Lady Macbeth into his or her stack.
Popping is possible with the word "recall". In the above
example, if we are using "recall", then it causes whoever Lady
Macbeth is speaking to, to pop an integer from his or her stack
and assume the value for him or herself.
A second example
Let us conclude with a small example to print numbers from 1 to
Romeo and Juliet learn to count numbers from 1 to 100.
Romeo , Helps in the process of counting.
Juliet, Starts from 1 and moves steadily to 100.
Act I: The counting machine.
Scene I: Decides to study number counting.
[Enter Romeo and Juliet]
Juliet: You are as bold as the square of the sum of a
mighty handsome brave king and a noble Lord.
Romeo: You are as lovely as a rose.
Scene II: Checks who is the fast learner.
Romeo: Open your heart.
Am I better than you?
Juliet: If not, let us proceed to Scene III.
You are as honest as the square root of yourself.
Speak your mind.
Romeo: You are as sweet as the sum of yourself and a plum.
Juliet: You are as gentle as the square of yourself.
Let us return to Scene II.
Scene III: Reaches an agreement.
You are as trustworthy as the square root of yourself.
Speak your mind.
In the above example, the first statement of Juliet stores
the value=100 in Romeo. Juliet moves from 1 to 100 and always
compares her value with Romeo to know whether the upper limit is
reached. The value of Juliet is printed. It is followed by a
newline character, which is a contribution from Romeo. When the
upper limit of 100 is reached the control moves to Scene III,
which is the end. The rest of the program is self-explanatory.
More examples are provided in the front end package. Also
a word list is given, showing all the possible words, which can be
included in your spl programs. You can make your own contributions
to the wordlist as well as to the examples.