LOADING 0%
// nav_menu.exe
Home Resume Blog Contact Order
English فارسی
~/blog / programming / goya-persian-programming-language

Goya: A Programming Language in Persian

For a while the idea of building a Persian programming language had been on my mind — a language whose Persian-ness is not limited to translating a handful of commands, but that is designed with the Persian language in mind from the start. That idea became Goya: a Persian programming language that I developed and released as open source.

Goya: A Programming Language in Persian
In Goya you can write code with Persian structure and words, use Persian digits, and see both output and error messages in Persian.
For example, a simple program in Goya can look like this:
salam-ali.goya
نام = "علی"
 
اگر نام == "علی"
    بگو("سلام علی!")
وگرنه
    بگو("سلام!")
Defining a function works the same way:
morabba.goya
تابع مربع(عدد)
    برگردان عدد * عدد
 
بگو(مربع(۷))
Output:
output
۴۹
Commands such as اگر (if), وگرنه (else), برای هر (for each), تابع (function), برگردان (return) and بگو (print) are part of the language itself, and Persian digits such as ۱۲۳ can be used directly inside the code.

# Persian-language support

While designing Goya I tried to take the details of the Persian language itself into account as well.
For example, differences between Persian and Arabic characters such as ی and ي, or ک and ك, are handled as far as possible so that they do not get in the way when you write Persian code.
Error messages are in Persian too, and when a program runs into a problem, errors are displayed in a way that fits the language itself.
Goya also supports the Shamsi (Jalali) calendar. For example:
emrooz.goya
بگو(امروز())
It shows the current date in the Shamsi calendar.

# The Goya development environment

To make the language easier to work with, I also built a Persian, right-to-left IDE for Goya.
You can try the language directly in your browser without installing anything:
Run Goya online
The IDE can also be run locally:
terminal
$ python -m goya ide
On top of that, Goya has an interactive environment, or REPL:
terminal
$ python -m goya repl
For example:
REPL example
گویا> ۲ + ۳ * ۴
=> ۱۴
This environment is handy for trying out commands and short pieces of code quickly.

# How the language is built

Goya has its own engine: I wrote the lexer, the parser, the AST and the interpreter from scratch. Goya code is not translated into Python and run; the source becomes tokens, the tokens become a program tree, and that tree is evaluated directly — there is no Python exec or eval anywhere in the engine.
The interpreter itself is written in Python; that is a practical choice, the same pattern Clojure uses on the Java Virtual Machine. In other words, Python is the implementation language of Goya, not a layer that runs Goya code.
My goal was that the Persian-ness of the language would not be only skin-deep, and that the different parts of the project would be designed with the same approach — from the syntax and the digits to the errors, the date and the development environment.
I also prepared several sample programs for the project so that the different features of the language are easier to see and try.

# Open source

The full source of Goya is published on GitHub under the MIT license, where you can see the language code, the examples and how the project is developing:
View the Goya source on GitHub
There is also a separate page that introduces the project and gives access to Goya's tools:
The Goya website
And if you just want to try the language quickly:
The Goya online IDE
Goya is still evolving, and the source is available so that anyone interested in programming-language design, Persian language processing, or the project itself can review the code and take part in its development.

# Related Posts