Shakespeare Programming Language
The Shakespeare Programming Language (SPL) is an esoteric programming language developed in 2001 by Jon Åslund and Kalle Hasselström, designed to enable the creation of programs structured as Shakespearean plays, where characters represent variables, dialogues perform computations, and acts and scenes manage control flow.[1][2]
Created as an assignment for a university syntax analysis course, SPL draws inspiration from the dramatic style of William Shakespeare's works, aiming to produce "beautiful source code" that mimics theatrical scripts rather than traditional code syntax.[1][2] Programs begin with a title and list of Dramatis Personae to declare characters (variables), followed by one or more acts containing scenes of dialogue; only two characters can appear on stage at once, using pronouns like "you" or "thou" to reference each other.[1][2]
Key operations in SPL rely on verbose, literary expressions: assignments use phrases like "You are as [adjective] as [expression]," where adjectives and nouns encode numerical constants (e.g., "a brave" equals 2, based on powers of 2 and word categories); arithmetic involves comparatives such as "better than" for addition or "the sum of" for summation.[1] Input is handled by imperatives like "Listen to your heart" for numbers or "Open your mind" for characters, while output uses "Speak your mind" or "Open your heart" accordingly; control structures include conditionals phrased as questions (e.g., "Am I better than you? If so, let us proceed to scene II") and scene jumps for loops or gotos.[1] The language is Turing-complete, as demonstrated by translations from Brainfuck, and supports integer variables with associated stacks for advanced operations, though it lacks formal typing beyond dramatic conventions.[1]
SPL's humorous and artistic nature has made it a staple in the esoteric programming community, with implementations available as translators to C and examples including classics like Hello World and a truth machine; its file extension is typically .spl, and it emphasizes readability as poetry over practical utility.[1][2]
Overview
Origins and Purpose
The Shakespeare Programming Language (SPL) was created in 2001 by Swedish students Jon Åslund and Karl Hasselström as part of a laboratory assignment in a syntax analysis course at the Royal Institute of Technology (KTH) in Stockholm, Sweden.[1][3] The project emerged from their interest in unconventional programming paradigms, aiming to develop an esoteric language that would transform typical code into something resembling a dramatic script inspired by William Shakespeare's works. This endeavor was completed largely in a single intensive session, highlighting the playful and experimental nature of academic exercises in computer science at the time.[4]
The primary purpose of SPL was to design a Turing-complete programming language whose source code mimics the structure and style of Shakespearean plays, prioritizing aesthetic appeal and readability as literature over conventional programming efficiency.[1] By incorporating elements like character dialogues and dramatic conventions into its syntax, the creators sought to satirize the rigidity of traditional programming languages while demonstrating that even whimsical constructs could achieve full computational expressiveness. This approach not only served as an educational tool for exploring parsers and compilers but also contributed to the burgeoning field of esoteric programming languages, which emphasize creativity, humor, and non-practicality.[3]
The initial implementation included a specification and a compiler written in C, which translated SPL programs into executable C code.[1] It was first shared publicly through student-hosted websites at KTH, such as personal pages under the domain d.kth.se, before being hosted on SourceForge for broader distribution within online programming communities.[3] This early 2000s release aligned with a wave of esoteric languages that challenged norms of code legibility, positioning SPL as a notable example of how literary inspiration could intersect with computational theory to produce both amusement and insight.[5]
Key Features
The Shakespeare Programming Language (SPL) is Turing complete, capable of simulating any Turing machine through its stack-based operations for each variable and conditional jumps implemented via interrogative dialogue structures. This computational power is achieved without loops or recursion primitives, relying instead on goto-like scene transitions and stack manipulation to emulate arbitrary computation, as demonstrated by mappings to equivalent Brainfuck programs using two characters' stacks.[5]
Variables in SPL are exclusively named after characters from Shakespearean plays, such as Romeo or Juliet, with each character representing a stack of signed integers initialized to zero upon first use. Computations operate solely on integer arithmetic, with no support for other data types like floats, strings, or booleans; all values are treated as signed integers, typically implemented as 32-bit or 64-bit in interpreters, though the language specification does not mandate a fixed size.[6]
Numerical constants are encoded using natural language phrases composed of adjectives modifying a noun, where the noun provides a base value of +1 for positive or neutral connotations (e.g., "horse") and -1 for negative ones (e.g., "pig"), and each preceding adjective multiplies this base by 2, yielding values of the form ±2^k for k adjectives. Examples include "a good horse" equaling +2 and "an artless pig" equaling -2, enabling representation of powers of two in positive or negative form without direct numerals. This system prioritizes poetic expression over conventional numeric literals.[1][5]
Operations are expressed through English verbs and phrases in character dialogue, distinguishing between assignment (e.g., forms of "to be" like "you are"), arithmetic (e.g., addition via comparative "as [adjectives] as"), and tests (e.g., "thou art" for equality checks leading to conditional branches). Nouns serve as operands referencing variables or constants, integrating seamlessly into dramatic speech. Whitespace within dialogue lines is ignored for parsing flexibility, allowing varied phrasing while maintaining readability, though the overall play structure demands precise formatting for acts, scenes, and character entries.[7]
Language Structure
Program Title and Dramatis Personae
The Shakespeare Programming Language (SPL) program begins with a mandatory title, formatted as a dramatic phrase ending in a period, which serves no semantic purpose but establishes the play-like structure of the code.[1] For example, a title might read "Romeo and Juliet." or "The Tempest of Computation.", consisting of any printable characters except newlines and periods before the terminating period.[1] This element mimics the opening of a Shakespearean script, enhancing the language's aesthetic goal of readable, poetic code without affecting execution.[2]
Following the title is the Dramatis Personae section, where all variables are declared as named characters, each on a separate line in the format "CharacterName, a descriptive phrase.".[1] The character name becomes the variable identifier, holding an integer value that defaults to 0 unless assigned otherwise through program dialogue; descriptions are ignored syntactically but must contain at least one non-whitespace character and end with a period.[1] Variable names are case-insensitive and must be unique within the program, conventionally drawn from characters in Shakespeare's works—such as Romeo or Ophelia—though this restriction is not strictly enforced in all implementations.[2] At least two characters must be declared to enable interactions, as the language limits simultaneous stage presence to a maximum of two for operations.[1]
Variable scoping is global across the program, allowing reference by name from anywhere, but access and manipulation are restricted to characters currently on stage, managed via enter and exit directives; off-stage characters cannot participate in dialogue until re-entered.[1] The Dramatis Personae section concludes after the final character declaration, typically marked by a blank line or the onset of the first Act declaration, transitioning the script to its executable structure.[1] These characters later form the basis for dialogue, where they exchange lines to perform computations and control flow.[1]
Acts, Scenes, and Character Management
In the Shakespeare Programming Language (SPL), programs are structured hierarchically into acts and scenes, mimicking the organization of a theatrical play to encapsulate blocks of code. An act is declared using the format "Act I: [description].", where the Roman numeral begins at I and increments sequentially for subsequent acts, with at least one act required per program.[1] Scenes, which serve as sub-blocks within acts and also function as labels for control flow jumps, follow the format "Scene I: [description].", requiring at least one scene per act.[1] This structure allows for a logical division of the program's logic, with execution proceeding linearly from the first scene of the first act onward.[2]
Execution flows automatically through the scenes and acts in order, transitioning from the last scene of one act to the first scene of the next, unless redirected by explicit goto statements such as "Let us proceed to [scene label].".[1] While acts and scenes do not enforce strict nesting via indentation, their declarations implicitly organize the code into a sequential hierarchy, where scenes are contained within their parent acts.[2] This progression provides a natural container for dialogue-based instructions, ensuring that program logic unfolds in a play-like narrative sequence.
Character management in SPL controls the visibility and accessibility of variables, which are represented as characters from Shakespearean plays, through stage directions that simulate theatrical entry and exit. The "[Enter [Character]]" directive brings a single character (variable) onto the stage, making it active for use in subsequent dialogue, while "[Enter [Character1 and Character2]]" introduces up to two characters simultaneously, as SPL limits the stage to a maximum of two characters at any time to facilitate unambiguous dialogue between a speaker and listener.[1] Conversely, "[Exit [Character]]" removes a specific character from the stage, rendering it temporarily inaccessible, and "[Exeunt]" clears all characters from the stage, often used to end a logical block.[1] These commands dynamically manage which variables are "on stage," directly affecting their usability in operations.
Scope rules in SPL tie variable access strictly to stage presence: a character (variable) is only addressable in dialogue when on stage, where it can be referenced as "you" (for the listener) or "thyself" (for self-reference), with attempts to operate on off-stage variables resulting in runtime errors.[1] This mechanism ensures that assignments, inputs, and computations occur only among active characters, preventing ambiguity in pronoun-based references and enforcing a form of dynamic scoping tied to the program's theatrical flow.[2] By requiring characters to enter before use and exit afterward, SPL maintains clear boundaries for variable interactions within acts and scenes, aligning computational logic with dramatic staging.[1]
The dialogue format serves as the core mechanism for encoding executable instructions in the Shakespeare Programming Language (SPL), where lines of text mimic spoken exchanges between characters to represent operations. Each dialogue line begins with the name of a speaking character followed by a colon, such as "[Character]: [line of text]", and must conclude with a period, question mark, or exclamation mark to delineate the statement's boundary and trigger parsing.[1] This structure ensures that the program's "script" flows naturally like a play, with the colon separating the speaker from their utterance.
Parsing of dialogue lines follows a rule-based interpretation that transforms literary phrasing into computational actions, ignoring non-essential grammatical elements to focus on semantically significant words. The first word after the colon typically functions as a verb, dictating the primary action of the line, while subsequent words are classified as adjectives (often representing numerical modifiers), nouns (denoting variables or entities), or other categories that contribute to the operation's operands. Articles, prepositions, and conjunctions are systematically disregarded during this process, allowing the language to prioritize poetic expression over strict syntax.[1]
Punctuation plays a subtle yet critical role in modulating the line's effect: periods and exclamation marks terminate declarative statements, executing the parsed operation directly (e.g., for assignments or input/output), with the chosen punctuation appended to output results where applicable; a question mark indicates a conditional comparison (e.g., "Am I better than you?"), which is followed by an "If so..." or "If not..." line to direct control flow to a specific scene, while for non-conditional lines it appends a question mark to outputs.[1] Indentation is optional and employed primarily for visual readability, helping to nest dialogue within scenes, though all executable lines must appear after a scene's declaration to maintain program flow; character scope, established upon entry in prior structural elements, applies to these interactions without altering the dialogue itself.[1]
In cases of invalid lines, such as those containing unrecognized words or malformed structures, SPL implementations halt execution immediately, preventing further processing to enforce syntactic integrity.[1] This error handling underscores the language's reliance on precise adherence to its parsing conventions, ensuring that only valid Shakespearean-inspired dialogue advances the program's computation.
Programming Constructs
Variables, Assignments, and Constants
In the Shakespeare Programming Language (SPL), variables are represented by the names of characters listed in the Dramatis Personae section of a program, with each variable storing an integer value. All variables are implicitly initialized to 0 when first referenced or when the corresponding character enters the stage, and their values can be reassigned multiple times through subsequent dialogue.[1][2]
Assignments follow a declarative syntax embedded in spoken lines, typically structured as "You are [expression]" or "Thou art [expression]," where the listener (addressed as "you" or "thou") receives the new value from the expression, which can involve variables, constants, or arithmetic results. For instance, a speaker addressing Romeo can say "You are as good as Juliet." to copy Juliet's current value to Romeo. More expressive assignments use phrases like "Thou art as lovely as the sum of Romeo and Juliet," which computes and assigns the sum of the two variables' values to the addressed character (thou). Pronouns must match the gender of the listener as defined in the Dramatis Personae.[1][2]
Constants in SPL are expressed without numeric literals, relying instead on natural language phrases consisting of an optional article, a sequence of adjectives, and a noun, where the base value derives from the noun's connotation (positive or neutral nouns yield +1, negative nouns yield -1) and each preceding adjective multiplies the magnitude by 2. Positive integers are built by stacking adjectives before a positive noun, such as "a cat" for 1 (a neutral noun) or "as fair as a cat" for 2 (one adjective doubling the base). Larger values follow this pattern, yielding powers of 2. Negative constants incorporate negative adjectives or nouns.[1][2][7]
Arithmetic operators are integrated into verbose English phrases rather than symbols, allowing operations on variables or constants within assignment expressions; the language defines binary and unary forms. Binary operators include "the sum of" for addition, "the difference between" for subtraction, "the product of" for multiplication, "the quotient between" for integer division, and "the remainder of the quotient between" for modulo. Unary operators encompass "the square of" for squaring, "the cube of" for cubing, "the square root of" for integer square root, "the factorial of" for factorial, and "twice" for doubling. These enable computations like "the product of Romeo and the sum of Juliet and a cat," which multiplies Romeo's value by (Juliet's value + 1).[1][2][7]
Complex expressions chain these elements using pronouns like "thyself" or "yourself" for self-reference, nouns for constants, and operator phrases for computations, all within a single assignment line. An example is "Thou art the sum of thyself and a cat," which increments the addressed variable by 1 (adding its current value to the constant 1). Such chaining supports intricate integer manipulations while maintaining the language's dramatic, conversational style.[1][2]
In the Shakespeare Programming Language (SPL), input and output operations are integrated into the dialogue structure, using imperative phrases that direct characters to interact with standard input and output streams, with no support for file I/O or other external devices. Output is triggered by a speaking character instructing a target variable (the listener) to reveal its value through specific body-part metaphors. The syntax has the speaker say "Open thy heart!" (adjusted for pronoun and gender) to cause the listener's integer value to be printed as a decimal number to stdout without any formatting. Similarly, "Speak thy mind!" outputs the value as an ASCII character. These commands adhere to Shakespearean grammar, where the pronoun ("thy," "his," or "her") matches the gender and person of the target variable as defined in the Dramatis Personae section.[1][2]
Input follows a parallel structure, where a speaking character directs a target variable (listener) to receive data from stdin using phrases like "Listen to thy heart!" to read an integer value into the listener; if the input is non-numeric, it is treated as 0 to ensure program continuity. For single-character input, the syntax employs "Open thy mind!", storing the ASCII value directly. Pronoun selection remains consistent with output, emphasizing the second-person form in addressed dialogue. All input is read from stdin line-by-line, and operations are limited to console interactions, reinforcing SPL's focus on theatrical simplicity over complex system access.[1][2]
These I/O mechanisms tie directly to variable management, where characters serve as variables holding integer values, which can be positive or negative. For instance, after assigning a value to a variable in a prior scene (as covered in variable assignment basics), an output command like a speaker saying to Juliet "Open thy heart!" would display that value numerically. Error handling is minimalistic: invalid integer inputs default to 0 without halting execution, and character inputs assume valid ASCII ranges, promoting robust yet dramatic program flow. This design ensures SPL programs remain console-bound, outputting solely to stdout for portability across implementations.[1][2]
Control Flow and Conditionals
Control flow in the Shakespeare Programming Language (SPL) relies on the hierarchical structure of acts and scenes to organize execution, with branching and looping facilitated by conditional questions embedded in character dialogue. Unlike conventional languages with explicit if-else or loop keywords, SPL uses natural-language queries to compare numerical values assigned to characters, determining whether to proceed linearly or jump to a different part of the play. This approach integrates control logic seamlessly into the Shakespearean narrative, making programs read like dramatic scripts while enabling Turing-complete behavior.[1]
The core of conditionals is the question syntax, where one character (representing the left operand) poses a query to another (the right operand) in the form "[Subject] [verb] [comparative] [object]?", with the verb often being "is" or "am" for dramatic effect. For instance, "Am I as good as you?" evaluates whether the value of the speaker equals that of the listener, branching based on equality if true. The question mark is mandatory to invoke conditional execution; without it, the line is treated as ordinary dialogue or an assignment. These questions compare integer values stored in characters, treating the difference (left minus right) to determine truthiness.[1]
Comparisons are specified via comparative phrases, supporting seven distinct types through selected adjectives that convey relational operators on the value difference. The phrase "as [adjective] as" handles equality and inequality: positive adjectives like "good" or "large" test for exact equality (difference == 0), while negative adjectives like "bad" or "small" test for inequality (difference != 0). For ordered comparisons, "[adjective] than" is used without "as": positive adjectives like "better" or "large" indicate greater than (difference > 0), and negative ones like "poor" or "small" indicate less than (difference < 0). Negations extend these with "not," yielding "not as good as" (difference != 0), "not better than" (difference <= 0), and "not worse than" (difference >= 0), providing the full set of relational operators. Adjectives must align semantically—positive for favorable relations, negative for unfavorable—to maintain syntactic validity, drawing from Shakespearean lexicon for stylistic variety. These mappings allow precise control over branching without numerical literals in the condition itself.[1]
Branching follows the question's evaluation immediately in the subsequent line, typically spoken by the questioned character. If the condition is true (positive outcome), execution jumps forward to the specified next act or scene, phrased as "If so, let us proceed to [act/scene]". If false (negative outcome), it jumps backward to the previous act or scene, or simply continues to the next line if no explicit instruction is given. This asymmetric jumping—forward for true, backward for false—enables if-then constructs and simple gotos, but restricts direct backward loops to prevent unstructured control flow. For example:
Juliet: Am I better than you?
Romeo: If so, let us proceed to scene II.
Juliet: Am I better than you?
Romeo: If so, let us proceed to scene II.
Here, if Juliet's value exceeds Romeo's (true), the program advances to Scene II; otherwise, it continues after the response line. Such gotos reference acts or scenes by Roman numerals, providing labeled targets within the play's structure.[1]
Looping is implemented indirectly via these conditional gotos, repeating sections by jumping between scenes or acts until a condition fails. There are no dedicated while or for constructs; instead, repetition relies on crafting questions that conditionally return to an earlier scene, often using negative outcomes for backward jumps. However, true backward loops require careful structuring, as direct infinite recursion is avoided; programmers simulate iteration through nested scenes or recursive calls via character interactions, ensuring termination via changing values. For instance, a loop might conditionally jump back to Scene I from Scene II if a value remains nonzero, decrementing in each iteration until equality holds. This method emphasizes the language's dramatic flow, where loops emerge from escalating or resolving plot tensions between characters.[1]
Stack Operations
In the Shakespeare Programming Language (SPL), each character functions as a variable backed by its own last-in, first-out (LIFO) stack of integers, enabling advanced data handling beyond simple scalar values. The current value of a character is the top element of its stack; if the stack is empty, this value defaults to 0. These per-character stacks serve as auxiliary storage for temporary values during computations, particularly useful given the language's restriction to binary arithmetic operations in expressions. There is no specified limit on stack size, allowing unbounded growth, though pops from an empty stack consistently yield 0 to prevent errors.[1][2]
Push operations add a value to the top of a character's stack via dialogue commands. A speaking character addresses a listener (which may be itself) with a line beginning "Remember" followed by an object specifier, such as a pronoun or noun phrase representing a value. For instance, "Remember me" instructs the listener to push the speaker's current value onto the listener's stack. Similarly, "Remember yourself" pushes the listener's current value onto its own stack. In general form, "[Speaker]: Remember [object]." evaluates the [object]—which could denote another character (variable), a constant (via adjectives and nouns), or the speaker/listener—and pushes that value onto the listener's stack. This mechanism extends variable capabilities for multi-operand scenarios, often combined with assignment statements like "You are [expression]" to update the top-of-stack value directly.[1][2]
Romeo: You are as pure as the sum of [Ophelia](/page/Ophelia) and a [cat](/page/Cat).
[Enter Juliet]
Romeo: Remember me.
Romeo: You are as pure as the sum of [Ophelia](/page/Ophelia) and a [cat](/page/Cat).
[Enter Juliet]
Romeo: Remember me.
In this example, Juliet (the listener) pushes Romeo's current value onto her stack after Romeo's initial assignment sets his value.[1][2]
Pop operations retrieve and assign the top stack value through "Recall" commands. A speaking character addresses a listener with a line beginning "Recall" followed by arbitrary descriptive text, which is semantically ignored. The effect is that the speaker pops the top value from the listener's stack and assigns it as the speaker's new top-of-stack value (yielding 0 if empty). The syntax "[Speaker]: Recall [ignored text]." thus transfers data from one character's stack to another, facilitating temporary storage and retrieval in algorithms requiring more than two operands. This, alongside assignments, supports SPL's Turing completeness by simulating arbitrary memory access.[1][2]
[Enter Romeo]
Juliet: Recall your tragic fate.
[Enter Romeo]
Juliet: Recall your tragic fate.
Here, Romeo (listener) has his stack popped, and the value (or 0 if empty) becomes Juliet's new value. No explicit handling for stack overflow exists, as stacks grow dynamically without bounds.[1][2]
Examples
Hello World Program
The standard "Hello World" program in the Shakespeare Programming Language (SPL), known as the "Infamous Hello World Program," exemplifies the language's verbose, play-like structure while demonstrating essential output mechanics through character dialogue that constructs and prints ASCII values. This program outputs the string "Hello World!" by assigning numerical values corresponding to ASCII codes to characters via elaborate expressions and invoking output commands.[1]
The full program is as follows:
The Infamous Hello World Program.
Romeo, a young man with a remarkable patience.
Juliet, a likewise young woman of remarkable grace.
Ophelia, a remarkable woman much in dispute with Hamlet.
Hamlet, the flatterer of Andersen Insulting A/S.
Act I: Hamlet's insults and flattery.
Scene I: The insulting of Romeo.
[Enter Hamlet and Romeo]
Hamlet:
You lying stupid fatherless big smelly half-witted coward!
You are as stupid as the difference between a handsome rich brave
hero and thyself! Speak your mind!
You are as brave as the sum of your fat little stuffed misused dusty
old rotten codpiece and a beautiful fair warm peaceful sunny summer's
day. You are as healthy as the difference between the sum of the
sweetest reddest rose and my father and yourself! Speak your mind!
You are as cowardly as the sum of yourself and the difference
between a big mighty proud kingdom and a horse. Speak your mind.
Speak your mind!
[Exit Romeo]
Scene II: The praising of Juliet.
[Enter Juliet]
Hamlet:
Thou art as sweet as the sum of the sum of Romeo and his horse and his
black cat! Speak thy mind!
[Exit Juliet]
Scene III: The praising of Ophelia.
[Enter Ophelia]
Hamlet:
Thou art as beautiful as the difference between Romeo and the square
of a huge green peaceful tree. Speak thy mind!
Thou art as lovely as the product of a large rural town and my amazing
bottomless embroidered purse. Speak thy mind!
Thou art as loving as the product of the bluest clearest sweetest sky
and the sum of a squirrel and a white horse. Thou art as beautiful as
the difference between Juliet and thyself. Speak thy mind!
[Exeunt Ophelia and Hamlet]
Act II: Behind Hamlet's back.
Scene I: Romeo and Juliet's conversation.
[Enter Romeo and Juliet]
Romeo:
Speak your mind. You are as worried as the sum of yourself and the
difference between my small smooth hamster and my nose. Speak your
mind!
Juliet:
Speak YOUR mind! You are as bad as Hamlet! You are as small as the
difference between the square of the difference between my little pony
and your big hairy hound and the cube of your sorry little
codpiece. Speak your mind!
[Exit Romeo]
Scene II: Juliet and Ophelia's conversation.
[Enter Ophelia]
Juliet:
Thou art as good as the quotient between Romeo and the sum of a small
furry animal and a leech. Speak your mind!
Ophelia:
Thou art as disgusting as the quotient between Romeo and twice the
difference between a mistletoe and an oozing infected blister! Speak
thy mind!
[Exeunt]
The Infamous Hello World Program.
Romeo, a young man with a remarkable patience.
Juliet, a likewise young woman of remarkable grace.
Ophelia, a remarkable woman much in dispute with Hamlet.
Hamlet, the flatterer of Andersen Insulting A/S.
Act I: Hamlet's insults and flattery.
Scene I: The insulting of Romeo.
[Enter Hamlet and Romeo]
Hamlet:
You lying stupid fatherless big smelly half-witted coward!
You are as stupid as the difference between a handsome rich brave
hero and thyself! Speak your mind!
You are as brave as the sum of your fat little stuffed misused dusty
old rotten codpiece and a beautiful fair warm peaceful sunny summer's
day. You are as healthy as the difference between the sum of the
sweetest reddest rose and my father and yourself! Speak your mind!
You are as cowardly as the sum of yourself and the difference
between a big mighty proud kingdom and a horse. Speak your mind.
Speak your mind!
[Exit Romeo]
Scene II: The praising of Juliet.
[Enter Juliet]
Hamlet:
Thou art as sweet as the sum of the sum of Romeo and his horse and his
black cat! Speak thy mind!
[Exit Juliet]
Scene III: The praising of Ophelia.
[Enter Ophelia]
Hamlet:
Thou art as beautiful as the difference between Romeo and the square
of a huge green peaceful tree. Speak thy mind!
Thou art as lovely as the product of a large rural town and my amazing
bottomless embroidered purse. Speak thy mind!
Thou art as loving as the product of the bluest clearest sweetest sky
and the sum of a squirrel and a white horse. Thou art as beautiful as
the difference between Juliet and thyself. Speak thy mind!
[Exeunt Ophelia and Hamlet]
Act II: Behind Hamlet's back.
Scene I: Romeo and Juliet's conversation.
[Enter Romeo and Juliet]
Romeo:
Speak your mind. You are as worried as the sum of yourself and the
difference between my small smooth hamster and my nose. Speak your
mind!
Juliet:
Speak YOUR mind! You are as bad as Hamlet! You are as small as the
difference between the square of the difference between my little pony
and your big hairy hound and the cube of your sorry little
codpiece. Speak your mind!
[Exit Romeo]
Scene II: Juliet and Ophelia's conversation.
[Enter Ophelia]
Juliet:
Thou art as good as the quotient between Romeo and the sum of a small
furry animal and a leech. Speak your mind!
Ophelia:
Thou art as disgusting as the quotient between Romeo and twice the
difference between a mistletoe and an oozing infected blister! Speak
thy mind!
[Exeunt]
This program is notable for its length—over 100 lines—primarily due to the descriptive phrases required to construct numerical constants through arithmetic operations in the dialogue. In SPL, characters represent variables holding integer values, and sentences perform operations on these values. The program declares four characters and uses acts and scenes for structure, with stage directions managing active variables. Through a series of assignments using similes and operations like sums, differences, products, and quotients, the values are set to the ASCII codes for the characters in "Hello World", which are then output sequentially via "Speak your mind!" commands. Constants are evaluated based on adjective counts and noun types (positive or negative contexts yielding powers of 2 with signs). The program relies on direct assignments rather than stacks for this simple output. Variations exist that use more advanced features like loops or input.[1]
Arithmetic Calculation Example
SPL supports arithmetic operations through verbose expressions in dialogue, enabling computations like addition, multiplication, and looping for tasks such as calculating factorials. A representative example is an iterative program that demonstrates variable assignments for increment and multiplication, conditional jumps for loop control, numeric and character output, and goto-based iteration to compute factorials up to a fixed limit (e.g., 16!), printing results in a formatted manner. Supporting characters can hold ASCII values for formatting (e.g., space, "=", "!", newline). The loop typically initializes an index and result variable, prints the current state, updates the index (e.g., adding 1 via "You are as [positive] as the sum of yourself and [unit noun]"), multiplies the result by the index (e.g., "You are as [adjective] as the product of myself and yourself"), and checks a condition (e.g., "Am I better than [expression evaluating to limit]? If so, [goto]") to continue until the limit is reached. Input can initialize the limit dynamically via "Listen to your heart!". For verified implementations and full code examples, see community resources like the Esolang wiki or Progopedia, as specific programs may vary in exact phrasing but illustrate the language's Turing completeness for arithmetic tasks.[1][2]
Simple Addition Example
For a basic demonstration of arithmetic, consider a program that adds two input numbers and outputs the result numerically. Characters represent the inputs (e.g., Romeo for first number, Juliet for second), loaded via "Open your heart!" or "Listen to your heart!". The sum is assigned via dialogue like "Thou art as good as the sum of thyself and Romeo." The result is output with "Open your heart!". A minimal example:
Addition Play.
Romeo, first number.
Juliet, second number.
Result, the sum.
Act I: Compute Sum.
Scene I.
[Enter Romeo]
Romeo:
Open your heart!
[Exit Romeo]
[Enter Juliet]
Juliet:
Open your heart!
[Enter Result]
Romeo:
You are as thyself.
Juliet:
You are as thyself.
Result:
You are as good as the sum of Romeo and Juliet.
Open your heart!
[Exeunt]
Addition Play.
Romeo, first number.
Juliet, second number.
Result, the sum.
Act I: Compute Sum.
Scene I.
[Enter Romeo]
Romeo:
Open your heart!
[Exit Romeo]
[Enter Juliet]
Juliet:
Open your heart!
[Enter Result]
Romeo:
You are as thyself.
Juliet:
You are as thyself.
Result:
You are as good as the sum of Romeo and Juliet.
Open your heart!
[Exeunt]
This loads values into Romeo and Juliet, copies them to Result if needed, computes the sum, and prints it. Values are integers; inputs are read as numbers.[1]
Implementations
Compilers and Interpreters
The original implementation of the Shakespeare Programming Language (SPL) is a transpiler called spl2c, developed by its creators Jon Åslund and Karl Hasselström in 2001. Written in C and utilizing tools like GNU Bison for parsing and Flex for lexical analysis, spl2c converts SPL source code into equivalent C code, which can then be compiled and executed using a standard C compiler such as GCC.[1][8]
This command-line tool operates by processing an SPL file (e.g., spl2c < program.spl > program.c), enabling direct compilation of the resulting file (e.g., gcc program.c -o program).[9] It fully adheres to the SPL specification defined in the 2001 manual, supporting core elements like character-based variables, dramatic structure for control flow, and Shakespearean phrasing for operations, but lacks built-in debugging or extensions.[1]
Modern implementations expand accessibility with interpreters in various languages, all open-source and generally supporting the full SPL specification without an official standard library. A prominent Python interpreter, shakespearelang, is available as a PyPI package installable via pip install shakespearelang, allowing execution of SPL programs through command-line invocation (e.g., shakespearelang program.spl).[10] For web-based use, a JavaScript interpreter is integrated into Esolang Park, an online platform for esoteric languages, enabling browser-based execution and testing of SPL code without local setup.[11][1] These tools maintain the language's esoteric nature by requiring custom parsers for its theatrical syntax, with occasional additions like syntax highlighting in online demos, but they share limitations such as no standardized extensions or libraries beyond the core spec.[1][6]
The Esolangs wiki serves as the primary online resource for the Shakespeare Programming Language (SPL), hosting a comprehensive specification, detailed instructions, and example programs such as the canonical "Hello World" and a "Truth Machine" implementation.[1] Established as part of the esoteric programming languages wiki since its inception around 2005, the page encourages community edits and includes tools like Brain2Speare, a converter from Brainfuck to SPL syntax.[1][12]
Community-driven development thrives on platforms like GitHub, where users have contributed numerous interpreters and compilers, including a Python-based interpreter and a compiler targeting C.[6][13] Repositories also feature collections of example programs, such as arithmetic algorithms and variations on classic tasks, alongside gists for simple demonstrations like "Hello World."[14][15][16] SPL has gained traction in code golf challenges, where participants optimize programs for brevity, with dedicated tips shared on forums for minimizing character counts in Shakespearean-style code.[17]
SPL's cultural footprint extends to educational contexts, where it promotes creative coding by blending literary expression with programming concepts, as highlighted in tutorials and introductory talks on esoteric languages, including a 2025 analysis of esolangs' pedagogical value.[18][19][20] It appears in resources on esoteric programming, such as a 2010s guide discussing SPL's role in challenging conventional syntax and inspiring unconventional problem-solving.[5] Academic discussions further underscore its value in enhancing programming skills through constrained, artistic paradigms.[20]