Shakespeare Programming Language

from Wikipedia, the free encyclopedia

The Shakespeare Programming Language ( SPL ) is an imperative esoteric programming language (computer language) developed by Karl Hasselström and Jon Åslund in 2001 , which was realized in C and is one of the most difficult programming languages ​​to learn. Similar to the Chef programming language , an SPL program looks like something completely different: At first glance, an SPL program looks as if it were a drama by William Shakespeare and follows its typical structure, but this does not mean that Shakespeare's original works can be understood as SPL and would be compilable!

SPL clearly demonstrates that a functioning programming language concept does not have to follow conventional ideas. In principle, structure and keywords only have to correspond to a fixed scheme in order to allow a clear interpretation, regardless of how legible or logical the program text appears to a person. Conversely, SPL programs are very easy to read, even for people who cannot program, as drama. The meaning for the (uninitiated) person and for the computer are completely different here, two meanings overlap. Therefore, SPL is often used in teaching as an example of language design.

How the two meanings overlap, which elements from Shakespeare's dramas correspond to which elements of a programming language, is shown below.

Basic knowledge

The Shakespeare Programming Language is special in terms of syntax, as it is not based on arithmetic and fixed characters like all other programming languages, but allows the developer a lot of freedom in his program. The developer often has the option of using the same program functionality by exchanging real language elements such as B. to achieve nouns or adjectives.

In addition, the programming language is based on William Shakespeare (you can program in drama form , so to speak ), which makes it unique, but also takes some getting used to.

The following examples are from the first program in SPL - the Hello World program . However, more complex programs such as B. program a program for determining prime numbers , as the developer demonstrates in his documentation with a few examples.

functionality

The title

The first line of every "play" in SPL is the title. This can be chosen freely and gives the piece a little more order and clarity. Since it can be freely selected, the compiler only recognizes it as a comment and therefore does not influence the program functionality. As a result, the title is optional, but the developers point out that an untitled program is as poorly programmed as an untitled drama is poorly written.

Example:

The Infamous Hello World Program

The characters (Dramatis Personæ)

As in every Shakespearean drama, the people must first be determined. These are the first lines of code that are recognized by the compiler as declaration instructions and must be recognized so that the formal aspects of a programming language can be guaranteed. All characters of the play are listed, which are always followed by a short description.

Example:

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.

The characters are similar to signed integer - variable or Chars , the means of operating system-specific character set tables clearly numerical values can be assigned. The following description of the character is mandatory, but is ignored by the parser . Only characters that also play a role in Shakespeare's dramas can be used, i.e. mostly Romeo , Juliet, Hamlet , Othello , Macbeth , King Lear , etc. Valid characters are recognized by means of an enclosed list of words, which currently comprises 152 characters.

Nudes and scenes

After the variables or characters have been declared, the sequence of a drama follows "Act I" and "Scene I", each of which is given a title. As with the program title, these are only treated as comments by the compiler; After compiling in C, however, “Act” and “Scene” are regarded as jump labels , which can be jumped to using “GOTO” / jump instructions.

As with the title, files and scenes are not absolutely necessary for successful compilation. However, they are not optional in the interests of the programmer, since every programmer in SPL as well as every playwright should be obliged to structure his program / work in acts and scenes so that legibility and clarity can be guaranteed.

Example:

Act I: Hamlet’s insults and flattery.
Scene I: The insulting of Romeo.

Enter, Exit and Exeunt

Each scene in each act is enclosed by keywords that open and close the scene. As in a drama that was written in Early New English, these are initially called “[Enter]”, “[Exit]” and “[Exeunt]”. In order to let a character speak and thereby make the program do something, the characters have to be on stage according to logic. Characters that address other characters already on stage with “you”, “thou” or any other second person pronoun must also be placed on the stage. Characters come onto the stage by specifying their "[Enter]" command as a kind of parameter.

Example:

[Enter Hamlet and Romeo]

Accordingly, characters step off the stage again. This is done either with the "[Exit]" or the "[Exeunt]" command. If a figure leaves, it must be mentioned after the "[Exit]", e.g. B. "[Exit Romeo]". However, if two or more characters resign at the same time, the "Exeunt" command must be used. The end of a scene is a special situation: in this case, all the people depicted often step away. A single "[Exeunt]" without any parameters is sufficient to inform the compiler of this.

If you give an “Enter” command to a character who is already on stage or an “Exit” to an absent character, the compiler reports a runtime error.

Example:

[Exeunt]
[Exeunt Hamlet and Romeo]

Dialogue / instructions

As in real drama, dialogue is mostly the basis of any instructions in SPL. Simple instructions such as assignments of arithmetic and logical expressions and procedural instructions ( input and output ), but also structured control instructions ( jump instructions or conditional instructions ) are permitted. A dialogue part of a single character consists of a character name, a colon and one or more sentences that represent the specific instructions.

Example:

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!

Literals

In SPL, literals or constants are defined by a word list, of which there are three in total: negative noun, neutral noun and positive noun. Any English word from the same word list family can be used synonymously. The literals thus correspond to predefined literary constants to which numerical values ​​can be assigned according to the following criteria:

  • Every noun is basically a constant with the value 1 or −1.
  • The exact value depends on whether the noun has a negative or positive connotation or whether one cannot make a statement about one's transferring mood:
    • "Flower" is z. B. a constant with the value 1.
    • "Pig" or "negation" would have been −1 accordingly.
    • "Tree" is z. B. neutral, as it does not transfer a certain mood and accordingly has the value 1.

Adjectives are also given special consideration in SPL. They are also divided into the three categories negative, neutral and positive using word lists:

  • Every adjective has to correspond in mood to the noun. A “stinking flower” also makes little sense from a Shakespearean point of view.
  • Each preceding adjective multiplies the noun by two.

Assignments

The variable assignment already known from other programming languages and the access to these variables (represented in SPL by the characters of Shakespeare's works) is implemented in SPL as follows:

  • For variable assignments, it is only permissible to use a second person pronoun (namely “you”, “thee” and “thou”) followed by an expression. This expression can be divided into two categories as follows:
    • Assignment of a literal: In this case, the program assigns the other character a direct literal in the form of a noun with an optional adjective in front of it. The other character that is on stage overwrites the previous value in his stack with the value of the literal.
      You lying stupid fatherless big smelly half-witted coward!
      
      In this case the stack of the addressed character is extended by the value −64.
    • Assignment of an expression: In this case the program assigns the result of an arithmetic expression (see below) to the other character. For this, it is absolutely necessary to specify an assignment operator, which must be placed between the variable and the expression in the form "as [any adjective] as".
      You are as stupid as the difference between a handsome rich brave hero and thyself!
      
      This example also explains that the values ​​of previous variables can be used in calculations. The reflexive pronouns "thyself", "yourself" and "myself" are valid . Assuming the other person's name is "Hamlet", the above instruction would correspond to the following assignment: "Hamlet = 8 - Hamlet".

Expressions

Using the methodology described above, SPL would only be able to express any natural powers to base 2 or the inverted base 2 for addition. Therefore, the possibility was created in SPL to implement arithmetic and propositional expressions.

Arithmetic expressions

An arithmetic expression consists of previously defined English words that describe mathematical operations. B. the four basic mathematical arithmetic operations “difference”, “sum”, “product” and “quotient”, but also extended expressions such as “square” or “cube” are permitted. These operations can be linked with "and" as required and require appropriate linguistic correctness. There must be either literals or variables between the arithmetic expressions:

A slightly more complicated example:

„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“

First you replace the constants with numbers. The sentence thus changes to:

„the difference between the square of the difference between 2 and -4 and the cube of −4“

Now the difference between 2 and -4 is 6 and the third power of −4 is (−4) 3 (= −64). Since the square of 6 = 36, the bottom line is “the difference between 36 and −64”, which corresponds to exactly 100. Thus "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" = 100.

Propositional expressions

Comparisons consist of propositional expressions that have a Boolean return value. Let and be arbitrary ordinal data types :

  • "Is as good as " tests for = .
  • "Is better than " tests for > .
  • "Is worse than " tests for < .

Any other positive comparative comparator such as “bigger”, “fresher”, “friendlier”, “nicer” or “jollier” can be used for “better”.

Any other negative comparative comparator such as “punier” or “smaller” can also be used for “worse”.

If the test result is to be inverted, this can be implemented with a "not", such as B. "not as good as" or "not better than".

Input and output

Another character can be asked to use “Open your heart” or “Speak your mind” to output the value of his variable either numerically in the first case or as a character, depending on the computer's character set, in the second case . So several continuous calculations and the piece-wise output of characters for z. E.g. the character string "Hello world!" Is possible with only one variable.

Correspondingly, the input of values ​​behaves accordingly: "Listen to your heart." Enables the assignment of a numerical value to the addressed character, while "Open your mind." Can be used for a character. The values ​​can be entered using any supported input device ; this is usually done using the keyboard.

Control instructions

Jump instructions

The command, often known from computer science as "GOTO", enables the simplest iteration and was only used in older systems and is nowadays almost exclusively used by the significantly more structured and simplified loops (e.g. counting loops or head or foot-controlled loops) replaced. Nevertheless, there is the possibility of a GOTO command in SPL, since a simple implementation possibility of a jump instruction is regarded as an essential factor for the classification as a programming language.

The implementation in SPL is carried out using the key terms “Let us”, “We shall” or “We must” followed by “Return to scene [Roman numeral]” or “Proceed to [Roman numeral]” and means that you have to go to the appropriate place specified scene should jump. Please note that you can only jump within an act, but not between several acts.

Conditional statements

Conditional statements consist of two main fragments, as shown in the following example:

Juliet:

 Am I better than you?

Hamlet:

 If so, let us proceed to scene III.

First, a question is asked that is a comparison (propositional expression) and has either a true or a false return value (in computer science this is called a Boolean variable ).

This is followed by a conditional statement, beginning with “if so” or “if not” and a comma. The sentence after it is only carried out if the previous statement is true (or, if “if not” is used, it is correspondingly false).

Compiler

Structure of the steps to compile SPL

The developers of SPL did not write their own compiler for SPL, but did write a translator from SPL to C, which converts the SPL syntax into a valid C syntax with the following commands that can be executed under Linux :

./spl2c < hello.spl > hello.c
gcc -c hello.c
g++ hello.o libspl.a

In the first step the program code is converted from SPL to C with the program “spl2c” provided by the developer, then in the second step it is compiled with the C compiler gcc and with the help of the header file “spl.h” provided by the developer . In the last step, the compiled program module “hello.o” is linked to a library “libspl.a” also provided by the developer, and an executable program is created.

swell

  1. University of Notre Dame : Course AME 437: Control Systems Engineering Homework 3 (English) “For any two of the four differential equations you solved last week in 2.9.5, also verify your answer by plotting your solution and a solution obtained by numerically solving the equation using a fourth order Runge Kutta routine written in C, C ++, FORTRAN or the Shakespeare Programming Language. "
  2. West Virginia University : Course English 306: Topics in Humanities Computing ( Memento from May 13, 2008 in the Internet Archive ) (English) "Sept 16 Meadows, Pause and Effect, Chap 2
    McCloud," Time Frames "NMR
    Recommended: Shakespeare Programming Language , Scott McLoud, Cloudmakers, Liquid Stage, Jimmy Corrigan, Crutch, Devil's Tramping Ground, Memex Engine, Ambient Machines, demain / When I am King. "

Web links