FiM ++

Original author: Cereal Velocity
  • Transfer

One day at a lecture, a friend told me that there is a pony programming language (based on the series, of course). He said he saw it on reddit, but even after a long search I could only find an empty repository on Google Code without implementation details. I was very disappointed with this, but only for a few minutes, until I realized that I could write an implementation of this language myself. Perhaps it will not be good or even used in the sense that not everyone can write an interpreter for it, but I wanted to test my skills. I also like protracted jokes.

So, I present to your attention a rather raw version of the syntax of what I call FiM ++.

FiM ++ is a dynamically typed, interpreted, object oriented, and Turing-complete language for writing letters to Princess Celestia on behalf of any of the ponies (I used Twilight for my specification). Functions in the language are formatted as paragraphs of the letter. This is done so that the code can be easily read and be as similar as possible to a letter. Each such letter is a class, so each program can consist of several letters, if the user so desires. However, the minimum interpreted unit is a class, almost like in Java. The language does not support libraries, since we send letters, which means the code should be as light as possible. The required data types can be defined by the user.

Each class begins with a heading that is always the same:
Dear Princess Celestia: Letter One

The operator brackets for parts of the code have been removed since they violate the message format, but can be used if the user wishes. They will not be mentioned later, indents are used instead, almost like in Python. “Princess Celestia” is a reserved keyword for creating a class and therefore should always be the first recipient. 'Letter One' is the name of the class.

Interfaces can be added to the first line of the class header, separated by commas:
Dear Princess Celestia, and Princess Luna, and Princess Cadance: Letter One

Each interface is defined by paragraphs (functions) that must be inside the class. The usual class is called like this:
I wrote you another letter! It's titled Letter Two.

'Letter Two' is now an illustrated object and can be used as such; for example, it can be used to transfer a function from a new class to the current one. It can also declare an object for further use in the code:
I wrote you another letter!
// code 
// code
Oh, about that other letter. It's titled Letter Two!

The main function looks like this:
Today I learned 
	// code
	// code
	Your faithful student, Twilight Sparkle.

It never accepts arguments, such as, for example, command line arguments. The return value consists of the string "Your faithful student," and the argument, which is the name. Returning the value may not be necessary, depending on the interpreter.

Any other function looks like this:
I learned about ducks
// code
// code	

It is called by name, in this case 'friendship'. Returning values ​​is not strictly necessary and can be ignored. Of course, a function can be called with parameters:
I learned about friendship with Spike and Rarity
// code
// code

Spike and Rarity can now be used inside the function. All arguments are passed magically (just in case).

The “I” keyword works like the “self” operator in most languages. However, he does not refer to an instance of the class, but to the writer of the letter. It can be defined anywhere.

Assigning a variable looks like this:

Did you know that Spike is a dragon?

In this example, we assign the string value “dragon” to the variable “Spike”. Spike could also have any other value, and the exact data type is determined at runtime.

Despite the fact that the language is dynamically typed, certain checks are still performed during operations with two variables. If someone writes something like “Pinkie Pie goes on a date with a number,” then the interpreter will need to throw an exception, in this case a RidiculousException.

Loops in FiM ++:
I did this 100 times…
// code
// code	

This should be enough to write an interpreter for a given language. And one more thing: the reserved keyword “friendship” should always be interpreted as “magic”, otherwise you risk violating the foundations of the rule of the Universe in which Equestria is located.

Hello world

Dear Princess Celestia: Hello World!
Today I learned how to say Hello World!
I said “Hello World”!
That’s all about how to say Hello World!
Your faithful student, Twilight Sparkle.


A document that describes the current language specification
A simple JavaScript interpreter
Code example: 99 Jugs of Cider

Also popular now: