Skip to content

The Storyteller Language Specification

Dhruv Jimulia edited this page Aug 14, 2023 · 3 revisions

Storyteller is intended to give the programmer an unprecedented degree of literary freedom when it comes to the composition and structure of their programs.

Data Representation

Variables

In Storyteller, variables are characters in your plot. All variables in Storyteller must be constructed from uppercase letters, lowercase letters and spaces. In other words, variables must obey the following regex: [a-zA-Z\s]+. Variable names are case-sensitive, so prince, Prince, and pRinCe refer to the same variable. For multi-word variables, variable names are insensitive to the number of spaces between the words. That is, regardless of how many spaces are between the and wizard, it will always refer to the variable the wizard. Lastly, all variables only have one type: they are all unbounded integers.

Number Literals

Now, let's be honest: numbers are cool and all, but they are quite disappointing when they appear right in the middle of an intense action sequence. Therefore, Storyteller has a feature known as poetic number literals, which are essentially strings that represent numbers. In poetic number literals, the values of digits of a number are given by the lengths of the words. To allow the digit zero, and to compensate for a lack of suitable poetic one and two letter words, word lengths are parsed modulo 10. For example, BFG corresponds to the number literal 3, chocolate factory corresponds to 97, and marvellous corresponds to 0 (since 10 % 10 = 0).

Statements

In Storyteller, statements are sentences of the English language. Each statement can end with ., ? or !. There are many different types of statements, and each of their syntax and semantics are outlined below.

P.S. In the syntax of the different types of statements below, [VARIABLE] denotes a variable and [NUMBER_LITERAL] denotes a number literal. Also, the examples below use . as the end-of-sentence punctuation mark for simiplicity: however, ? or ! can also be used in its place.

Assignment Statements

The syntax of an assignment statement is as follows:

[VARIABLE] [TO_BE_KEYWORD] ([NUMBER_LITERAL] | [VARIABLE]).

The statement above assigns the value of ([NUMBER_LITERAL] | [VARIABLE]) to [VARIABLE]. The [TO_BE_KEYWORD] can take the following values: is, was, were, are, want to be like, wants to be like and wanted to be like.

As an example of an assignment statement, take Charlie was an incredible mathematician. This statement assigns Charlie to 203 if an incredible mathematician is not yet initialized as a variable. Otherwise, it assigns the value of the variable an incredible mathematician to Charlie.

Arithmetic Statements

An addition statement has the following syntax:

[VARIABLE] felt as [POSITIVE_ADJECTIVE] as ([NUMBER_LITERAL] | [VARIABLE]).

The statement below adds the value of the ([NUMBER_LITERAL] | [VARIABLE]) in the RHS to [VARIABLE] in the LHS. [POSITIVE_ADJECTIVE] can take multiple different values, including good, great, awesome, amazing, fantastic, wonderful and incredible. The full list of the different values [POSITIVE_ADJECTIVE] can take can be found here.

Conversely, the syntax of a subtraction statement is as follows:

[VARIABLE] felt as [NEGATIVE_ADJECTIVE] as ([NUMBER_LITERAL] | [VARIABLE]).

The statement below subtracts the value of ([NUMBER_LITERAL] | [VARIABLE]) from [VARIABLE]. Some values [NEGATIVE_ADJECTIVE] can take include bad, terrible, awful, horrible, dreadful, unpleasant, and miserable. All possible values of [NEGATIVE_ADJECTIVE] can take can be found here.

Input/Output Statements

Philosophically speaking, print statments are just variables of the program revealing their identity to the programmer, via the mysterious command-line terminal. Since dialogue allows writers to adeptly reveal the identity of their characters, in Storyteller, dialogue corresponds to print statements.

In particular, to print a variable as an integer, the following syntax is used:

"[QUOTE]", [VARIABLE] [SAID].

Since one of the design goals of Storyteller is to spur programmer creativity, [QUOTE] can be whatever you want your characters to speak. [SAID] can take multiple different values, including said, exclaimed, whispered, shouted, mumbled and replied. All possible values of [SAID] can be found here

In addition to printing the value of a variable as a number, Storyteller also allows you to print the value of a variable as a string. But since variables can only have integer values, the following algorithm is used to get a string representation of a number: every three digits of a number translates to an ASCII character, under modulo 128. The syntax to print a variable as a string is as follows:

"[QUOTE]", [VARIABLE] [SAID] [ADVERB].

[QUOTE], [VARIBLE] and [SAID] follow the same semantics as explained above for printing variables as numbers. [ADVERB] can be any word that ends with -ly.

Apart from print statements, Storyteller also offers input statements that allow the programmer to take user input. The syntax for input statements is as follows:

[VARIABLE] (looks|looked) up to the skies above, waiting for an answer.

This statement takes a line of user input, and converts the ASCII string input to a number (by translating each ASCII character as three digits of the resultant number), and assigns this number to the [VARIABLE].

Goto Statements

Any statement that a) does not match with any of the statements above b) contains go to, goes to, went to, gone to or going to followed by a [NUMBER_LITERAL] or [VARIABLE], is a goto statement.

Before understanding the semantics of goto statements, we first need to understand the semantics of paragrahs in Storyteller. Storyteller statements can be divided into paragraphs, where the paragraphs are separated by one or more instances of the newline character. The paragraphs are implicitly numbered as 0, 1, 2 and so on. Therefore, goto statements switch the control flow of the program switches to the beginning of the paragraph corresponding to the value of the [NUMBER_LITERAL] or [VARIABLE] following it.

Conditional Statements

The following is the syntax of conditional if statements in Storyteller:

If ([NUMBER_LITERAL]|[VARIABLE]) [CONDITIONAL_OPERATOR] ([NUMBER_LITERAL]|[VARIABLE]), then [STATEMENT].

The if statement above executes the [STATEMENT] if and only if the condition corresponding to ([NUMBER_LITERAL]|[VARIABLE]) [CONDITIONAL_OPERATOR] ([NUMBER_LITERAL]|[VARIABLE]) holds, the specifics of which are described below.

[STATEMENT] can refer to any statement desribed in this specification. [CONDITIONAL_OPERATOR] can match the following four patterns, each of which determines how the two ([NUMBER_LITERAL]|[VARIABLE]) are compared.

  • [TO_BE_KEYWORD] corresponds to equals
  • [TO_BE_KEYWORD] not corresponds to not equals
  • ([TO_BE_KEYWORD] | felt) [POSITIVE_COMPARATIVE_ADJECTIVE] than corresponds to greater than
  • ([TO_BE_KEYWORD] | felt) [NEGATIVE_COMPARATIVE_ADJECTIVE] than corresponds to less than

Here, [POSITIVE_COMPARATIVE_ADJECTIVE] can take the values better, greater, stronger and larger. Similarly, [NEGATIVE_COMPARATIVE_ADJECTIVE] can take the values worse, less, fewer, and smaller. Lastly, [TO_BE_KEYWORD] is as defined in the assignment statement section.

Exit Statements

Any statement that contains the word end and that does not match any of the statement patterns described above is an exit statement. The exit statement causes the program to exit with EXIT_SUCCESS.

Language Features

Comments

All other sentences that do not match the rules of the statements above is a comment. Comment use is considered highly idiomatic since it allows you to add eloquence and flair to your plot and characters.

Pronouns

The keywords he, she, him, her, they, them, ze, hir, zie, zir, xe, xem, ve, and ver can be used in place of a variable, and any of these pronouns refer to the last named variable.

Surbodinate Clauses

For any of the statements above, instead of ending the sentence directly with end-of-sentence punctuation, you can instead add a comma with a surbodinate clause following it. The surbodinating clause is entirely ignored, but can provide gripping and necessary context to your plot and characters.