📜 ⬆️ ⬇️

The implementation of the Euclidean algorithm on Shakespeare

As you know, there are now quite a few esoteric programming languages, among which there is the notorious Brainfuck.
This article will focus on the language of Shakespeare, which was developed by John Aslaud and Karl Hasselstrom. The purpose of creating this language is to mask the program code under the play of William Shakespeare. Since the program Hello, world! already parsed in the documentation and has a rather voluminous form, then we will try to write on it a fairly simple Euclidean algorithm for finding 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.
In this case, everything that does not belong to the first two groups, in this programming language, is considered a comment.

There is a natural question, how to distinguish between these words. But before we analyze the structure of the program.
')
The title of the program that performs the role is similar to the keyword program in Pascal, and does not carry any semantic meaning. Next comes the list of people who participate in the program. Everything that we declare here will be further our variables. The only restriction on the name of the variable is that it must be the name of the character from the play of Shakespeare.
Like any play, this program is divided into acts and scenes, which are numbered in Roman numerals. Acts and scenes play the role of tags for transitions, both conditional and unconditional.

In this language, nouns and adjectives play the role of bricks. In this case, the noun has a value of 1 or -1, depending on whether this 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 to the noun in front increases it by 2 times. With this knowledge, we can already get the 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, we can use the keyword thyself . 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, since they are given a positive meaning. Accordingly, the brave charming hero is represented as 1 * 2 * 2 = 4. The second sentence is divided into the sum of the number 2, which corresponds to the cute pony, and the value of the variable pointed to by the keyword thyself.
Translated into any programming language, the specified code fragment will look something like this:
 X = 4; X = 2 + X; 


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




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

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

Of course, aside, the hated transition operator, which is recorded in the form of “Let us return to” or “Proceed to”, followed by the indication of the scene or act to which it should go, did not remain aside.

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

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

Euclidean algorithm


First, we remind ourselves of the Euclidean algorithm in our familiar language, for example, C
 while (x != y) if (x > y) x = x - y; else y = y - x; 


Let's make the main backbone of our program, namely, variables and main commands. Any art inserts 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 will have in Dramatis Personae:
Romeo, a young man.
Hamlet, a woeful prince to be compared

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

Now let's get down to writing the code. We have several branching possibilities. Two scenes are created as 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 you see between your own 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 the difference between your own and Hamlet!
Am I braver than you?
If so, let us proceed to scene II



Conclusion


So, in this article we met 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.

Source: https://habr.com/ru/post/167363/


All Articles