Implementation of the Euclidean algorithm on Shakespeare

As you know, now there are quite a few esoteric programming languages, among which there is the notorious Brainfuck.
This article will focus on the Shakespeare language, which was developed by John Aslaud and Karl Hasselstrom. The purpose of creating this language is to disguise the program code for the plays of William Shakespeare. Since the program is Hello, world! Since it is already disassembled in the documentation and has a rather voluminous form, we will try to write on it a rather simple Euclidean algorithm to find the greatest common divisor of two integers.

a common part


All words of this language are divided into three types: keywords that are responsible for performing any actions, variables and comments.
At the same time, everything that does not belong to the first two groups in this programming language is considered a comment.

A natural question arises how to distinguish between these words. But first, let's analyze the structure of the program.

The name of the program, which performs a role similar to the program keyword in Pascal, and does not carry any semantic load. Next is a list of individuals who participate in the program. Everything that we declare here will continue to be our variables. The only restriction on the name of a variable is that it must be the name of a character from a Shakespeare play.
Like any play, this program is divided into acts and scenes, which are numbered in Roman numerals. Acts and scenes play the role of labels for transitions, both conditional and unconditional.

In this language, the role of brick is played by nouns and adjectives. Moreover, the noun has a value of 1 or -1, depending on whether the noun has a positive or negative meaning. The translator of this language contains dictionaries to correctly determine the meaning of a noun. Each adjective added in front of the noun increases it by 2 times. With the help of this knowledge, we can already get numbers that are a power of two, and opposite to them.
To get other numbers, use the keywords sum and difference. In addition, to find out the value of the variable we want to get, we can use the thyself keyword . For example, the number 6 can be obtained, for example, in the following way:

You are brave charming hero. You are as good as the sum of cute pony and thyself
In this method, the number 6 is represented as 4 + 2. The words hero and pony take the values ​​1, because they are given a positive meaning. Accordingly, brave charming hero is represented as 1 * 2 * 2 = 4. The second sentence is divided into the sum of 2, which corresponds to cute pony, and the value of the variable pointed to by the thyself keyword.
Translated into any programming language, the indicated code fragment will look something like this:
X = 4;
X = 2 + X;


The following phrases are used for input and output in this language:


  • Listen to your heart - this command assigns the entered number to the variable.
  • Open your mind - this command assigns the variable the numeric code of the entered character (i.e., at '0' the value of the variable will be 48)


In exactly the same way, phrases for output are written: Open your heart and Speak your mind, and now it will not be difficult for an attentive reader to understand what each of these phrases does.

As a conditional operator, phrases are used that are asked in the form of a question. Here, the distribution of adjectives into good and bad sense already plays a role.
For example, the question: “Am I happier than you?” entails a comparison whether the value of the variable that asks the question is greater than the value of its interlocutor. If we would like to compare for equality, we could ask “Am I as good as you” and use the “not” particle to invert the comparison.

Of course, the mentioned and hated transition operator, which is written in the form of “Let us return to” or “Proceed to”, which is followed by an indication of the scene or act to which it is necessary, did not stand aside by many.

Finally, we finish the general part by looking at the important keywords: Enter, Exit, and Exeunt, which show which variables are available at current times.
Enter accepts variable names as parameters, separated by commas, or separated by the word “and”, making them available
Exit takes only one variable name as a parameter, making it inaccessible.
Exeunt accepts the same parameters as Enter as parameters, making the corresponding variables inaccessible, or no parameters; in this case, all variables become unavailable.

In addition, all variables must be declared at the beginning of the program.

Euclidean Algorithm


First, let us recall the Euclidean algorithm in our usual language, for example, C
while (x != y)
 if (x > y)
  x = x - y;
else
  y = y - x;


We will compose the main backbone of our program, namely, variables and main teams. Any artistic insertions will remain with the reader.

So, first of all, we need to choose which characters will participate in our play. I will take, for example, Hamlet and Romeo.

So what we have in Dramatis Personae:
Romeo, a young man.
Hamlet, a woeful prince to be compared

Everything after the decimal point in this section of the program is regarded as a comment.

Now let's start compiling the code. We have several branching options. Two scenes are created, since we will go there by condition.
Act I: The Face
Scene I: Comparison
[Enter Prince Hamlet]
Hamlet:
Listen to your heart!
[Exit Prince Hamlet]
[Enter Romeo]
Romeo:
Listen to your heart!
[Enter Prince Hamlet]
Hamlet:
Let us proceed to scene II
Scene II: The Duel
Romeo:
Am I not as good as you?
Hamlet:
If so, let us proceed to scene III.
Romeo:
Speak your heart!
[Exeunt]

Scene III: Hamlet Dishonoured
Romeo:
Am I better than you?
If so, thou art as bold as difference between thyself and Romeo!
Am I better than you?
If so, let us proceed to scene II.
Am I better than you?
If not, let us proceed to scene IV.

Scene IV: Romeo Deceased
Hamlet:
Am I braver than you?
If so, thou art as bold as difference between thyself and Hamlet!
Am I braver than you?
If so, let us proceed to scene II



Conclusion


So, in this article we got acquainted with a rather entertaining esoteric language, the code of which is similar to the plays of the great English playwright William Shakespeare. That's all.

Also popular now: