Shakespeare

Appeared in:
2001
Paradigm:
Typing discipline:
File extensions:
.spl
Versions and implementations (Collapse all | Expand all):
Programming language

Shakespeare is an esoteric programming language, in which programs resemble plays by Shakespeare.

The language was created by Kalle Hasselström and Jon Åslund as part of their programming assignment in Syntax Analysis course. A couple of weeks before the authors discovered for themselves the world of [paradigm]esoteric programming languages, so they decided to create one of their own. The assignment didn’t require developing a compiler, so the authors only created a translator to C.

Language capabilities include arithmetics, character and numerical I/O, conditional jumps and gotos, and some basic stack operations. Language authors claim that Shakespeare combines the expressiveness of BASIC with the user-friendliness of assembly language.

Program Structure

  • Title — part of the program till the first full stop. Is treated as a comment.
  • Dramatis Personæ — variables declaration. Each variable is described as Name, description, where Name should be the name of any Shakespeare character (well, only the characters recognized by the interpreter), and description is treated as a comment. All variables store integer numbers; besides, each variable has a stack associated with it.
  • Program Body — consists of Acts and Scenes, indexed with Roman numerals. They serve as labels for conditional and unconditional jumps. Each scene, in turn, consists of a sequence of commands, disguised as lines spoken by characters.

Most of the commands require at least two characters on stage — the speaker and the person he addresses. Characters are put on and off stage by directives [Enter ...] and [Exit ...]. If everybody leaves the stage, [Exeunt] can be used.

Commands

All commands look as lines spoken by one character to another. Both must be on stage. Other characters can be mentioned, which may be off stage.

  • assigning a value to a variable X. The new value is an expression, constructed from constants and/or values of other variables, including X itself. The most common form is You are as <adjective> as <expression>.
  • character/integer output: Speak your mind! / Open your heart!.
  • character/integer input: Open your mind! / Listen to your heart!.
  • unconditional jump (goto): Let us return/proceed to scene II. The scene index has to be within the current act. It’s also possible to jump to another act, but only to its beginning.
  • conditional jump consists of two parts: checking some condition and the actual jump.
  • pushing value on the stack: Remember <expression>.
  • popping value off the stack and storing it in the speaking character: Recall <anything here>.

The constants in Shakespeare are given as a noun preceded by a sequence of adjectives. A noun corresponds to 1 or -1 depending on whether it’s nice or neutral (1) or bad (-1). Each adjective before a noun multiplies its value by 2; the adjectives must have the same sense-feeling as the noun, or be neutral. Thus, only powers of 2 can be expressed directly; all other numbers have to be constructed using arithmetics.

Elements of syntax:

Case-sensitivity no
Variable identifier regexp any character of any play by Shakespeare
Variable assignment You are <expression> / You are as <adjective> as <expression>
Variable declaration <name>, <description>
Variable declaration with assignment Scene <index>: <description>.
Physical (shallow) equality Am I as <adjective> as <expression>?
Comparison Am I better than <expression>?
If - then If so, let us proceed/return to scene <index>.

Examples:

Hello, World!:

Example for versions Lingua::Shakespeare 1.00

The message is printed in a simplest way: ASCII-code of each character is calculated anew as a sum of powers of two present in its binary notation.

use Lingua::Shakespeare;

Shakespeare-style Encoded Message.

Desdemona, the talker.
Pericles, a shut-pan with notable patience.

Act I: Message output.

Scene I: Letter by letter.

[Enter Desdemona and Pericles]

Desdemona:
  You honest reddest gentle loving sweet brave rose!
  You are as bottomless as the sum of yourself and a rural red purple hamster!
  Speak your mind!

  You bold cunning peaceful proud good sweetest hero!
  You are as pretty as the sum of thyself and a warm cunning cute fine delicious kingdom!
  You are as bottomless as the sum of yourself and a rural white morning!
  You are as small as the sum of yourself and a grandfather!
  Speak your mind!

  You sweetest proud happy prompt cunning loving joy!
  You are as embroidered as the sum of yourself and a reddest loving beautiful cunning handsome happiness!
  You are as reddest as the sum of yourself and a peaceful cunning beautiful pony!
  You are as rural as the sum of yourself and a white tiny sky!
  Speak your mind!
  Speak your mind!

  You healthy amazing loving clearest trustworthy good happiness!
  You are as brave as the sum of yourself and a cunning golden loving peaceful mighty pony!
  You are as delicious as the sum of thyself and a mighty rich gentle plum!
  You are as embroidered as the sum of yourself and a fine bold hero!
  You are as old as the sum of yourself and a tiny cat!
  You are as green as the sum of thyself and a stone wall!
  Speak your mind!

  You bottomless big blue purple huge horse!
  You are as lovely as the sum of thyself and a gentle prompt delicious Heaven!
  You are as red as the sum of yourself and a bottomless big moon!
  Speak your mind!

  You tiny red furry rural bottomless sky!
  Speak your mind!

  You rural bluest large bottomless little purple cow!
  You are as sweet as the sum of yourself and a embroidered cute trustworthy rich rose!
  You are as bottomless as the sum of yourself and a green normal cow!
  You are as proud as the sum of thyself and a handsome summer's day!
  You are as happy as the sum of thyself and a flower!
  Speak your mind!

  You tiny bluest large huge hard normal uncle!
  You are as warm as the sum of yourself and a pretty rich charming reddest mighty Heaven!
  You are as small as the sum of yourself and a huge green little morning!
  You are as sweetest as the sum of yourself and a beautiful sweet kingdom!
  You are as warm as the sum of yourself and a proud happiness!
  You are as hard as the sum of yourself and a roman!
  Speak your mind!

  You warm cute happy pretty golden loving Lord!
  You are as huge as the sum of thyself and a little furry small green yellow brother!
  You are as peaceful as the sum of thyself and a honest brave happy fine flower!
  You are as small as the sum of yourself and a yellow purse!
  Speak your mind!

  You normal purple rural old white big morning!
  You are as blossoming as the sum of yourself and a charming cunning gentle lovely amazing happiness!
  You are as normal as the sum of thyself and a large red big animal!
  You are as charming as the sum of yourself and a healthy delicious hero!
  Speak your mind!

  You large old bluest green red rural lantern!
  You are as sweet as the sum of yourself and a beautiful loving sunny mighty reddest summer's day!
  You are as lovely as the sum of yourself and a bold clearest happiness!
  Speak your mind!

  You golden loving fair charming lovely King!
  You are as rural as the sum of thyself and a squirrel!
  Speak your mind!

[Exeunt]

Factorial:

Example for versions Lingua::Shakespeare 1.00

This example uses iterative factorial definition. In scene I variables are initialized (except for loop index which is 0 by default), scene II is the loop which prints the current number, characters and the factorial, and then checks whether the current number is 17 — if it is, the loop breaks.

use Lingua::Shakespeare;

Elizabethan Factorial.

Ferdinand, for factorial.
Isabella, for loop index.
Emilia, for exclamation mark.
Sebastian, for space.
Egeus, for equality sign.
Lucio, for newline.

Act I: Factorial calculations.

Scene I: Initialization.

[Enter Isabella and Sebastian]

Isabella:
  You are as fat as the product of a big black furry old cat and a white cow!

[Exit Sebastian]
[Enter Emilia]

Isabella:
  You are as distasteful as the sum of Sebastian and a chihuahua!

[Exit Emilia]
[Enter Egeus]

Isabella:
  You are as good as the difference between the sum of Sebastian and Emilia and a bold brave hero!

[Exit Egeus]
[Enter Lucio]

Isabella:
  You are as cute as the sum of a peaceful warm delicious summer's day and a cute squirrel!

[Exit Lucio]
[Enter Ferdinand]

Isabella:
  You brother!

Scene II: Loop.

Ferdinand:
  Open your heart!

[Exit Ferdinand]
[Enter Emilia]

Isabella:
  Speak your mind!

[Exit Emilia]
[Enter Sebastian]

Isabella:
  Speak your mind!

[Exit Sebastian]
[Enter Egeus]

Isabella:
  Speak your mind!

[Exit Egeus]
[Enter Sebastian]

Isabella:
  Speak your mind!

[Exit Sebastian]
[Enter Ferdinand]

Isabella:
  Open your heart!

[Exit Ferdinand]
[Enter Lucio]

Isabella:
  Speak your mind!

[Exit Lucio]
[Enter Ferdinand]

Ferdinand:
  You are as good as the sum of yourself and a rose.

Isabella:
  You are as gentle as the product of myself and yourself.
  Am I not as beautiful as the sum of your sweet charming lovely noble sister and a flower?

Ferdinand:
  If so, let us return to scene II.

[Exeunt]

Fibonacci numbers:

Example for versions Lingua::Shakespeare 1.00

This example uses iterative method of calculating Fibonacci numbers. After the loop (end of scene II) loop counter Isabella is re-used to print full stops.

use Lingua::Shakespeare;

Fibonacci Numbers.

Isabella, the loop index.
Falstaff, a Fibonacci number.
Fortinbras, another Fibonacci number.
Sebastian, space.
Cordelia, comma.

Act I: Factorial calculations.

Scene I: Initialization.

[Enter Isabella and Sebastian]

Isabella:
  You are as fat as the product of a big black furry old cat and a white cow!

[Exit Sebastian]
[Enter Cordelia]

Isabella:
  You are as beautiful as the sum of Sebastian and the sum of a tiny yellow furry hamster and the clearest blue sky!

[Exit Cordelia]
[Enter Fortinbras]

Isabella:
  You father!

Scene II: Loop.

Isabella:
  Open your heart!
  You are as noble as the sum of yourself and Falstaff.

[Exit Fortinbras]
[Enter Falstaff]

Isabella:
  You are as brave as the difference between Fortinbras and yourself.

[Exit Falstaff]
[Enter Cordelia]

Isabella:
  Speak your mind!

[Exit Cordelia]
[Enter Sebastian]

Isabella:
  Speak your mind!

[Exit Sebastian]
[Enter Fortinbras]

Fortinbras:
  You are as good as the sum of yourself and a rose.

Isabella:
  Am I not as beautiful as your sweet charming lovely noble sister?

Fortinbras:
  If so, let us return to scene II.
  You are as good as the sum of Cordelia and a fine horse!
  Speak your mind! Speak your mind! Speak your mind!

[Exeunt]