Gregorovich

From Esolang
Jump to: navigation, search

Gregorovich is a Stack based esolang made by User: Jussef Swissen. It's programs are meant to be highly condensed and readable, and are output as a one-liner in output and executed. It applies exponential growth to each program.

Instructions

There are 10 instructions, all of which except three are mathematical operations. The other three are control flow, a loop, print instructions, and a register. This language also implements the use of exponential growth.

Instructions Function
x + y Adds x and y
x - y Subtracts x and y
x * y Multiplies x and y
x / y Divides x by y
x % y Mods x by y
# Prints string
Y Prints all the elements in the stack
I(x)[y] If statement with condition x and body y
W(x)[y] While loop with condition x and body y
Regx,y Stores value h in register x
^y Declares exponent y

How It Works

As stated before, a program in Gregorovich is supposed to be highlying condensed, but readable. Therefore, spaces are strictly prohibited, and are replaced by underscores. These underscores also separate statements on the same line. The program is always printed onto output along with any output produced by the program itself. This is to help with debugging programs which don't give the desired output. Standard operators, "=", "<", ">", "<=", ">=", "!=", "or, and "and", are allowed. The increment and decrement signs, "++", and "--" are allowed as well.

Exponents

Using the exponent instruction, "^", an exponent must be specified at the start of every Gregorovitch program. This exponent is added to every number in the program, and includes strings printed by the print instruction, "#". In the expression, 4 + 4, when the specified exponent is 2, the expression changes to 4^2 + 4^2, or 16 + 16, which is 32. e.g:

^2_#4+4

This prints:

^2_4+4
32

Math operations

You can perform any mathematical operation, that matches one of the following: Addition, Subtraction, Multiplication, Divison, and Modulus. Here is an example using each operation. It uses the exponent 1 for simplicity.

^1_#4+4_#4-4_#4*4_#4/4_#4%4

This prints:

^1_#4+4_#4-4_#4*4_#4/4_#4%4
8 0 16 1 0

Registers

Registers are used as variables in this language, and are very important. Registers are declared using the Reg instruction. The following example stores value 9 in register f, and prints it.

^1Regf,9#f

Printing

So far, we've been using the # for printing strings and the values of expressions. We can also use the dump command, Y, to print everything in the stack. e.g:

Regr,4_Regu,6_Y

This prints:

Regr,4_Regu,6_Y
4 6

Remember that if the stack is empty, the interpreter will return an error. When the specified exponent is more than 1, then the exponent induces a special property regarding printing strings and expressions. It prints the them n times, where n is the exponent. Take this as an example: ^2_Regd,2_W(d>0)[#O_d--]. It prints "O" 2 times initially. The exponent 2 makes the string also output 2 more times on the third line. Here's the output.

^2_Regd,2_W(d>0)[#O_d--]
O O
O O O O
O O O O O O O O
O O O O O O O O O O O O O O O O 
...

The 3 dots are not part of the actual output, but are added to help you understand that this exponential growth is shown executed forever.

Control Flow & Loop

This language uses the I instruction to declare if statements, and uses the W instruction to declare a while loop. The if statement and while loop is similar to their counterparts in C++, except the curly braces are replaced with square braces, and the if and while keywords are replaced with I and W, respectively. Here is a program that prints "Gregorovich" 7 times if the value in register a is equal to 7.

^1_rega,7_I(a==7)[W(a<0)[#Gregorovich_a--]] 

Which prints:

^1_rega,7_I(a==7)[W(a<0)[#Gregorovitch_a--]]
Gregorovich Gregorovich Gregorovich Gregorovich Gregorovich Gregorovich Gregorovich

Hello World Program

This program uses the exponent of 1.

^1_#Hello,world!

99 Bottles Program

This program uses the less and more symbol, "<" and ">", to enclose the register in the program. This can be used for any variable.

^1_Rega,99_W(a>1)[#<a>-bottles-of-beer-on-the-wall-<a>-bottles-of-beer,_a--_#take-one-down-and-pass-it-around-<a>-bottles-of-beer-on-the-wall.]_#1-bottle-of-beer-on-the-wall,1-bottle-of-beer,take-it-down-and-pass-it-around,no-more-bottles-of-beer-on-the-wall.

Implementation

There is no implementation as of yet. However, if you have one, feel free to add it here.