OSShakespeare.003 examines arithmetic expressions and output in the Shakespeare Programming Language (SPL), an experimental language that makes code resemble a stage play. Characters are integer-valued variables, speeches perform computations, and the listener receives assignments. The lesson builds on OSShakespeare.002 on characters, variables and stage addressing. Learners will construct and trace sums, differences, products and quotient expressions, then use a complete miniature play to produce a numerical result.
Learning Objectives and Prerequisites
- Explain how the original SPL vocabulary assigns integer values to nouns and adjectives.
- Translate the arithmetic phrases
the sum of,the difference between,the product of, andthe quotient betweeninto arithmetic operations. - Recognize unary
the square of,the cube of, andtwiceexpressions. - Distinguish the value of the speaker (
myself) from the value of the listener (thyself). - Trace successive assignments to a character and explain the meaning of
Open your heartversusSpeak your mind. - Identify grammar, stage, arithmetic-domain and integer-range errors, and validate an example with an actual SPL interpreter when available.
Prerequisites: SPL titles, character declarations, act and scene headings, entrances, and listener addressing from OSShakespeare.001 on program structure and OSShakespeare.002. A reader should be comfortable with addition, subtraction, multiplication, division, and signed integers. The practical exercise uses a plain-text editor; an SPL interpreter is optional for manual tracing but necessary to establish actual runtime behavior.
Elementary Overview
Imagine a play in which each actor carries a number rather than a prop. One actor speaks to another, giving the listener a new number. A compliment can mean a positive number, an insult can mean a negative number, and special phrases can add, subtract, multiply, or divide numbers. A wordy speech that sounds like literature can therefore contain a short mathematical instruction.
For example, a flower represents one, while a big flower represents two. Placing another allowed adjective before the same noun doubles the value again. A phrase such as the sum of thyself and a big flower adds two to the listener’s current number. The stage directions determine which character is listening.
The 2001 Language Specification
SPL was described by Karl Hasselström and Jon Åslund in documentation last rebuilt August 21, 2001. The authors used a translator from SPL to C and defined precise token and grammar rules. Not every English word, theatrical flourish, or mathematically understandable phrase is recognized by an interpreter. The original specification remains the primary reference for the examples here. Contemporary independent implementations, including shakespearelang, can offer more convenient interactive tools but may differ in setup and diagnostics.
The underlying language is designed for experimenting with parsing and programming-language design rather than replacing production languages. Its unusual syntax illustrates a central computer-science principle: a formal grammar can attach precise computational meaning to text that also carries an artistic interpretation. Readers interested in other experimental syntax can compare Emojicode and the unrelated Chef culinary programming language.
From Nouns and Adjectives to Integer Values
In the original SPL model, a recognized positive or neutral noun represents +1, whereas a recognized negative noun represents -1. Every valid adjective placed before a noun doubles the magnitude. The rule can be expressed as value = sign × 2n, where n is the number of recognized adjectives and sign depends on the noun class. In the core example, flower is a positive noun and big is a neutral adjective.
The following expression values follow directly from that rule:
a flower -> +1
a big flower -> +2
a big big flower -> +4
a pig -> -1
a big pig -> -2
value = noun_sign * (2 ** adjective_count)
Word recognition is finite: adding an unsupported word does not necessarily create a longer valid number phrase. The syntactic role of “big” as a recognized adjective matters more than how natural the sentence sounds. As a practical habit, check proposed adjectives and nouns against the compiler’s vocabulary, the original lexicon, or successful published examples.
Basic Arithmetic Phrases
Arithmetic operates on expressions, which may be simple numerical phrases, the current values of characters, or nested expressions. SPL uses fixed English-shaped constructs rather than symbolic operators such as + and *. The major binary forms are the sum of A and B, the difference between A and B, the product of A and B, and the quotient between A and B. The original grammar also includes a remainder form.
For clarity, the next examples use small operands and show their equivalent calculations. They are expression fragments, not complete runnable plays:
the sum of a big flower and a flower
-> 2 + 1 = 3
the difference between a big big flower and a flower
-> 4 - 1 = 3
the product of a big flower and a big big flower
-> 2 * 4 = 8
the quotient between a big big flower and a big flower
-> 4 / 2 = 2
Each phrase names the operation and supplies two arguments. The order of subtraction matters: A − B is generally different from B − A. Division requires care because SPL characters hold integers, and implementations may use integer-division semantics rather than producing floating-point fractions. Never divide by zero; it is not a meaningful numeric result in the reference model. Prefer exact divisions in an introductory lab to avoid rounding and compatibility ambiguity.
Unary Operations and Nested Expressions
Unary operators work on a single operand. The original language includes twice, the square of, the cube of, the square root of, and the factorial of. Square and cube mean powers of two and three, respectively, rather than multiplication by two and three. Square root and factorial raise additional domain and integer-overflow questions, so they should be tested within well-defined small inputs.
Consider the positive expression a big flower, which equals two. The following fragments have these values:
twice a big flower -> 2 * 2 = 4
the square of a big flower -> 2 ** 2 = 4
the cube of a big flower -> 2 ** 3 = 8
the factorial of a big flower -> 2! = 2
Expressions may be nested. The phrase the sum of the square of a big flower and a flower represents 2² + 1 = 5. Parentheses are a useful device in an explanatory translation to ordinary mathematics, but are not a substitute for SPL’s specific expression grammar. The original authors’ worked example also demonstrates nesting squares, differences, and cubes.
Speakers, Listeners, and Reassignment
A phrase beginning You are as good as is an assignment to the person being addressed, not to the speaker. If Romeo and Juliet are the two characters on stage and Romeo speaks, Juliet is the listener. Inside Romeo’s speech, thyself refers to Juliet’s present value. In a speaker-relative expression, myself refers to Romeo’s value. The actor addresses the listener while the arithmetic updates that listener.
A complete program therefore needs a title, supported character declarations, an act and scene, stage entrances, and valid dialogue. Assignments on subsequent sentences use the listener’s newly updated value. The language’s literary punctuation is part of parsing; do not assume a dialogue sentence without terminal punctuation is accepted.
A Complete Program That Prints an Integer
Save the following play as arithmetic.spl using a plain-text editor. It declares two variables, places them on stage, performs four assignments to Juliet while Romeo speaks, and emits Juliet’s final number using Open your heart. There is no input, network access, file modification, or privileged operation:
A Calculation in Two Voices.
Romeo, a young man of Verona.
Juliet, a gracious lady of Verona.
Act I: A Lesson in Numbers.
Scene I: The Arithmetic of the Heart.
[Enter Romeo and Juliet]
Romeo:
You are as good as a big big flower.
You are as good as the sum of thyself and a big flower.
You are as good as the product of thyself and a big flower.
You are as good as the difference between thyself and a flower.
Open your heart.
[Exeunt]
The initial Romeo and Juliet values are zero in the reference model. The first assignment sends Juliet a positive noun modified by two neutral adjectives, producing four. The second adds two to Juliet’s current four, the third multiplies the resulting six by two, and the fourth subtracts one from twelve. Open your heart then requests a decimal numeric representation of the addressee’s current value, rather than converting it into a character.
Manual Execution Trace and Expected Result
The sequence can be checked with ordinary integer arithmetic. It is a prediction based on the reference specification until an interpreter runs the complete program:
Juliet starts with 0
big big flower -> 4
sum of thyself and 2 -> 6
product of thyself and 2 -> 12
difference of thyself and 1 -> 11
Open your heart -> 11 (decimal output)
A separate arithmetic sanity check evaluates the same sequence using conventional calculations. Its value is eleven: ((4 + 2) × 2) − 1 = 11. That check establishes the intended mathematics, but does not prove the entire SPL file parses or runs on a specific interpreter.
Numeric Output Versus Character Output
SPL provides two different output commands. Open your heart outputs the listener’s value as a number; Speak your mind outputs the character corresponding to the listener’s numeric code, as interpreted by the runtime’s character encoding. A character code such as 65 might correspond to A in an ASCII-compatible environment, but its exact interpretation follows the runtime. Confusing these forms is a common reason a program prints a letter where a number was expected.
For a first lab, use Open your heart to avoid character encoding complications. If you replace the final output sentence with Speak your mind, Juliet’s value of eleven is typically a control-code value, not the visible string 11. The two commands should never be treated as interchangeable text formatting options.
Running the Play and Recording Evidence
The original 2001 system translates SPL into C, then uses a C compiler to produce an executable. Its documented spl2c pipeline assumes that the historical translator and runtime library have been built correctly for the local machine. A newer interpreter such as the independently maintained shakespearelang package may offer a simpler workflow and interactive debugging. Vendor packages, licenses, and install commands should be checked against their current official project documentation.
With the modern interpreter already installed in a disposable environment, first inspect the available command help, then run a local file using the documented command form. Do not run unfamiliar downloaded code with elevated privileges:
shakespeare --help
shakespeare run arithmetic.spl
If the installed implementation uses a different invocation, follow its current help text rather than copying a command blindly. Record the interpreter version, exit status, diagnostics, and actual output. A correct run should emit the decimal value eleven, although terminal formatting and whitespace may vary. The source and manual trace do not establish an executed result; no SPL interpreter run is represented as having occurred here.
Troubleshooting and Common Errors
- Unexpected value: count adjectives before each noun and check the noun’s positive or negative class. One extra adjective doubles magnitude.
- Wrong assignment target: verify which character speaks and who is the other character currently on stage. The listener receives the value.
- Unknown token or syntax error: compare the exact noun, adjective, operator phrase, punctuation, and stage heading against the original specification.
- Incorrect output type: use
Open your heartfor a decimal integer;Speak your mindfor a character code. - Division problems: avoid zero denominators; investigate integer truncation, negative values, and implementation-specific overflow behavior.
- Unexpected stage error: ensure the declared speaker and addressee are both present, and avoid extraneous actors that make addressing ambiguous.
- Tool version mismatch: the reference translator, independent modern interpreter, and educational ports do not all share identical installation and diagnostic behavior.
Exercises and Knowledge Check
- Change the first assignment from
a big big flowertoa big flower. Predict the new final numeric output. - Replace the final difference with
the sum of thyself and a flower. What value would the original four-step program then produce? - Explain why multiplying
a big flowerbya big big floweryields eight. - Explain the difference between the value of
thyselfandmyselfwhen Romeo is speaking to Juliet. - Describe when the phrase
the quotient between A and Bdiffers from floating-point division. - Explain why an interpreter test is necessary even after the mathematical trace is correct.
Answer key: The modified first assignment begins at two, so the remaining changes yield ((2 + 2) × 2) − 1 = 7. Replacing the last subtraction with addition yields ((4 + 2) × 2) + 1 = 13. Multiplication of two by four yields eight. With Romeo speaking, thyself refers to Juliet and myself to Romeo. Integer quotients may discard fractional parts according to runtime semantics. A mathematical trace cannot detect an invalid lexeme, malformed sentence, or interpreter compatibility defect.
Primary Sources and Further Reading
- Karl Hasselström and Jon Åslund — The Shakespeare Programming Language (original 2001 documentation).
- Original Shakespeare Programming Language specification (PDF copy).
- shakespearelang — modern open-source interpreter, interactive console and debugger.
- Voxxed Days Crete 2025 — Ted Neward’s esoteric languages talk.
- NDC London 2020 — Dylan Beattie’s The Art of Code.
Elementary Conclusion
SPL can express real arithmetic using ordinary-looking theatrical sentences. Recognized adjectives double the number represented by a noun, while certain phrases add, subtract, multiply, or divide values. The person being spoken to receives the new number. In the example play, Juliet’s value moves from four to six to twelve to eleven, and the final speech asks the computer to print eleven as a number. The same logic can be understood in conventional arithmetic, but a running program must still be tested with a compatible interpreter.
Editor’s Note: OSShakespeare.003 follows the verified published OSShakespeare.002 curriculum and uses the original 2001 specification as its primary technical reference. The numeric output 11 is a mathematically checked, specification-derived expectation; SPL interpreter execution has not been independently demonstrated. The original 1200 × 630 featured image depicts fictional stage characters and is labeled conceptual editorial illustration, not an interpreter screenshot. The two conference videos were matched to published programs and their reported Shakespeare segments, but embedded playback and mobile appearance remain subject to live inspection.

We volunteer daily to ensure the information on this platform is Verifiably True. If you would like to support the research, please scan the QR code. Before making any payment, independently verify the receiving address and requested amount in your wallet.
Educational examples are provided for learning programming-language syntax and are not intended for production infrastructure or security-sensitive applications.

Leave a Reply