DotnetBard 0.1.0

dotnet add package DotnetBard --version 0.1.0
                    
NuGet\Install-Package DotnetBard -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotnetBard" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotnetBard" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DotnetBard" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotnetBard --version 0.1.0
                    
#r "nuget: DotnetBard, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotnetBard@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotnetBard&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DotnetBard&version=0.1.0
                    
Install as a Cake Tool

The-Dotnet-Bard

English | 中文

An interpreter for the Shakespeare Programming Language (SPL), written in C# on .NET 10.

SPL programs look like Shakespeare plays: characters are variables, dialogue is computation, and the drama is Turing-complete.

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!

(Characters hold signed integers. A noun is a constant - nice nouns are +1, nasty ones −1 - and every adjective doubles it. "Speak your mind" prints the value as a character.)

SPL specification document: The Shakespeare Programming Language (PDF)

  • Karl Hasselström & Jon Åslund, 2001.

Features

  • Complete SPL: character declarations, acts & scenes as jump labels, enter/exit/exeunt stage directions, assignments, a full set of arithmetic operations (see below), questions and conditional sentences (if so / if not), gotos, per-character stacks (remember / recall), numeric and character I/O.
  • Faithful to the original spl2c where the spec is silent - including two features the popular Python implementation lacks:
    • jumps to an act (spec §4.2), not just scenes;
    • not-inverted comparisons ("Am I not better than you?", spec §4.3.1) and less + adjective comparatives.
  • 32 documented language decisions for everything the spec leaves ambiguous (division semantics, EOF handling, integer width, Unicode output, …): docs/spec-decisions.md.
  • Hand-written lexer + recursive-descent parser - zero runtime dependencies.
  • Precise parse/runtime errors with source line and context.
  • Interactive console (REPL).

Arithmetic

Values are 64-bit signed integers. An operand is a constant (a noun phrase), a character name (that character's current value, on stage or not), or a nested operation - phrases compose freely, e.g. the sum of the square of Romeo and twice a happy cat.

SPL phrase Meaning Notes
the sum of X and Y X + Y
the difference between X and Y X − Y
the product of X and Y X × Y
the quotient between X and Y X ÷ Y truncated toward zero; zero divisor = runtime error
the remainder of the quotient between X and Y X mod Y same truncation semantics as division
the square of X X²
the cube of X X³
the square root of X ⌊√X⌋ truncated down; negative operand = runtime error
twice X 2X
the factorial of X X! negative operand = runtime error

Constants: a noun is +1 (nice) or −1 (nasty), and every adjective doubles it - any adjective may modify any noun, regardless of tone; nothing and zero are 0. Arithmetic overflow wraps. Rulings: D3, D6, D9–D13.

Comments: asides ( ... )

The original SPL spec has no comment syntax - it declares the title and descriptions to be the comments. This interpreter deliberately extends the language with parenthetical asides: in the theatre, parenthesized text is spoken to the audience and unheard by the other characters - here, it is unheard by the interpreter.

Romeo:
  You are as brave as the sum of yourself and a cat!   (Romeo += 1)
  (The loop below runs until Juliet speaks her mind.)
  Let us return to scene II.

An aside runs from ( to the next ), may appear anywhere whitespace may appear, and may span lines; asides do not nest. Asides apply to code only: inside the title and the character/act/scene descriptions, parentheses remain ordinary text - so the spec's own appendix plays (e.g. the Ghost's parenthesized description in primes.spl) keep parsing unchanged. Ruling: D8.

Requirements

Usage

Command line

Run a play file to completion:

dotnet run --project src/DotnetBard.Cli -- run samples/hello_world.spl

Start the interactive console (REPL) - enter a sentence, event, or expression on each line; exit to quit:

dotnet run --project src/DotnetBard.Cli -- console
dotnet run --project src/DotnetBard.Cli -- console --characters Hamlet,Ophelia

Prebuilt self-contained binaries for linux-x64, win-x64, osx-arm64, and osx-x64 are attached to each release.

As a library

Add the package and drive the interpreter from C#:

dotnet add package DotnetBard
using DotnetBard;
using DotnetBard.IO;

var source = """
    Two.
    Romeo, a young man.
    Juliet, a young woman.
    Act I: Counting.
    Scene I: The sum.
    [Enter Romeo and Juliet]
    Romeo: You are as bold as the sum of a cat and a cat. Open your heart!
    [Exeunt]
    """;

var interpreter = new ShakespeareInterpreter(source, Settings.Basic);
interpreter.Run(); // prints 2

Examples

The samples/ directory holds example plays, each with expected input and output (see samples/README.md):

  • hello_world.spl - prints Hello World!
  • reverse.spl - reads characters and prints them reversed
  • primes.spl - reads a bound N and prints the primes up to N
  • fibonacci2.spl - prints the Fibonacci sequence
  • guess.spl - a number-guessing game
  • shakesbeer.spl - "99 bottles of beer"
  • sum.spl / double.spl / max.spl / total.spl - small originals with aside comments: two-number sum, double, max, and a running-total loop

Project layout

src/DotnetBard/        Core interpreter library (no third-party dependencies)
src/DotnetBard.Cli/    Command-line front end (run / console)
tests/DotnetBard.Tests/ xUnit test suite
samples/               Example plays (see samples/README.md)
docs/                  Design documents

Documentation

License

This project is licensed under AGPL-3.0-or-later - see LICENSE.

It contains material from spl2c (the original SPL-to-C translator), Copyright © 2001 Karl Hasselström & Jon Åslund, licensed GPL-2.0-or-later: the vocabulary files (src/DotnetBard/Vocabulary/) and six sample plays in samples/ (the other four samples are original to this project); see NOTICE for details. The fibonacci.spl example from spl2c is deliberately omitted: it relies on spl2c's error-recovery (a bare You are <expression> without the as…as frame, and a stray the before twice), which this interpreter rejects as parse errors under its strict assignment grammar (D32). See samples/README.md for each sample's source and expected input/output.

Acknowledgments

Special thanks to zmbc/shakespearelang

  • the Python SPL interpreter by Zeb Burke-Conte whose architecture this project follows, and whose test suite guided the design.

Thanks also to Karl Hasselström & Jon Åslund for creating SPL and the original spl2c, and for documenting it with such humor.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 172 7/30/2026