Šaral – Šariš Algorithmic Language
I would like to introduce you with newest top level evolution in information crunching. It is a problem-science-tech-oriented programming language Šaral. The famous šariš-american company IBM have always been trying to create a languge, which a computer would understand as good as human understands
This page summarizes informations about implementation of Šaral programming language for Java Virtual Machine.
Not all features are currently supported. Current implementation can be found on Šaral GitHub repo.
Compiler
We need to have maven installed.
Šaral source files have srl
extension and we can compile it to JVM bytecode. It outputs a .class
file.
1 |
java com.pidanic.saral.Compiler <saral_source_file.srl> |
Then run compiled program.
1 |
java <saral_source_file.class> |
Program
It is for JVM, but you do not need to have class
es. We declare few variables with meňak
and print them to the console with ciskaj
.
1 2 3 4 |
meňak neskutočné numeralio five = 5 ciskaj five meňak slovo hello = "hello" ciskaj hello |
Second option to print something to the console is to use povidz
. It is equivalent to ciskaj
.
1 2 3 4 |
meňak neskutočné numeralio five = 5 povidz five meňak slovo hello = "hello" povidz hello |
Comments
They start with //
and can appear at the beginning of a line and they will take whole line or at the end of a statement
1 2 3 4 5 |
meňak neskutočné numeralio five = 5 // this is a comment ciskaj five meňak slovo hello = "hello" // nice greeting ciskaj hello |
Constants
There is one type of variables (meňak
), which value might be changed. But there exist a constant (furt
), which values can not be changed.
1 2 3 4 5 |
meňak neskutočné numeralio number = 5 meňak slovo hello // might be "empty" (not initialized) // meňak value might be changed number = 6 hello = "hello" |
1 2 3 4 5 6 |
furt neskutočné numeralio same_number = 5 furt slovo only_hello = "servus" // will not work, furt can not be changed // same_number = 6 // only_hello = "hello" |
Data types
There are following data types supported – neskutočné numeralio
, slovo
, logický
, písmeno
, skutočné numeralio
.
neskutočné numeralio
represents integers. Using JVM platform, one could use them with following range [-9223372036854775808; 9223372036854775807]
or [-263; 263-1]
.
skutočné numeralio
are for real numbers, expressed as decimals in range approximately
2-1074 <= x <= (2-2-52) × 21023
.
Type písmeno
is a single character, that is a letter, a digit, a punctuation mark, a tab, a space or something similar. A char literal is a single one character enclosed in single quote marks (apostrophes).
slovo
is sequence of characters enclosed in double quotes.
Type logický
represents boolean/kleene values – pravda
(true
), skoroošaľ
(undefined
), ošaľ
(false
).
1 2 3 4 5 6 7 8 |
meňak neskutočné numeralio five = 5 meňak slovo hello = "hello" meňak logický p = pravda meňak logický o = ošaľ meňak logický so = skoroošaľ meňak skutočné numeralio number = 1.2 meňak písmeno ch = 'a' meňak neskutočné numeralio bigNumber = 5000000000 |
Arrays
The array are created using the keyword funduš
. Each array have to be initialized with its length. Each data type can be used in array.
1 2 3 4 5 6 7 8 |
furt neskutočné numeralio n = 10 funduš logický l[n] funduš skutočné numeralio sn[n * n] funduš neskutočné numeralio nn[n] // there is optional 'dimenzion' keyword before 'funduš' dimenzionfunduš písmeno p[n] dimenzion funduš slovo s[n] |
Šaral initialize each element of a array similar way JVM does (neskutočné numeralio
– 0
, skutočné numeralio
– 0.0
, logický
– ošaľ
, písmeno
– (empty space),
slovo
– (java) null
)
Array elements
To access individual elements in arrays, we use bracket with element index inside them. Index of an element is referenced from 0
to array length - 1
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
l[1] = pravda l[2] = skoroošaľ l[3] = ošaľ nn[0] = 1 nn[1] = 2 nn[2] = 3 nn[3] = 4 p[0] = 'A' s[0] = "aa" ciskaj n ciskaj p[0] ciskaj sn[0] ciskaj nn[0] ciskaj s[0] ciskaj l[0] ciskaj l[1] ciskaj l[2] ciskaj l[3] |
Type slovo
as array of písmeno
The type slovo
has a special meaning in Šaral programming language. We could use it as array of characters (type funduš písmeno
).
We could access an index or change it to the value we want on a given index.
(It is possible to change characters in constants – furt slovo
. It works same as in arrays, because we change only the characters not the whole value).
1 2 3 4 5 |
furt slovo test = "test" ciskaj test[1] // 'e' test[1] = 'a' ciskaj test // "tast" |
In case we access the index of character that is greater than string length, the output is null character (\0
, \u0000
) in Šaral.
1 |
ciskaj test[6] // '\u0000' |
Operations
Arithmetic operations
There are supported mathematical operation between integers, floats and characters (type neskutočné numeralio
, skutočné numeralio
, písmeno
) with precedence of parentheses and operations.
- multiplication
*
- division
/
or:
- addition
+
- substraction
-
- remainder (modulo)
%
(does not work for typeskutočné numeralio
) - negation
-
(unary minus, does not work forpísmeno
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
bar neskutočné numeralio returnSomething() meňak neskutočné numeralio five = 5 vrac five meňak neskutočné numeralio aa = 1 + 1 meňak neskutočné numeralio b = 2 * 10 meňak neskutočné numeralio c = 10 - (vrac mi z baru vracimDaco()) meňak neskutočné numeralio d = (1 + 1) * 3 meňak neskutočné numeralio e = (10 / 2) meňak neskutočné numeralio f = (10 : 2) meňak neskutočné numeralio g = 11 % 2 meňak neskutočné numeralio h = -aa meňak skutočné numeralio i = 1.0 meňak skutočné numeralio j = -i meňak skutočné numeralio l = 1 + 1.0 furt písmeno char1 = 'A' - 'A' furt písmeno char2 = 'A' + 1 furt písmeno char3 = 'A' + 'A' furt písmeno char4 = '.' * 2 furt písmeno char5 = 'a' / 2 furt písmeno char6 = 'c' % 2 |
String concatenation
+
operation has a second meaning in Šaral language – string concatenation (slovo
type).
1 2 3 4 |
furt slovo s1 = "hello" furt slovo s2 = " world" furt slovo s3 = s1 + s2 ciskaj s3 // "hello world" |
It is enough, that one of both expression is type of slovo
.
1 2 3 |
furt neskutočné numeralio num = 1 furt slovo s4 = s1 + num ciskaj s4 // "hello 1" |
Comparisons
One can compare expressions with same type on both sides (type neskutočné numeralio
or skutočné numeralio
):
- equal
==
- not equal
<>
- greater than
>
- greater or equal
>=
- less than
<
- less or equal
<=
A result will be pravda
(true) value or ošaľ
(false) value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
meňak logický e = 4 == 4 meňak logický e2 = 4 == 3 meňak logický ne = 4 <> 4 meňak logický ne2 = 4 <> 3 meňak logický ge = 4 >= 4 meňak logický ge2 = 4 >= 3 meňak logický ge3 = 3 >= 4 meňak logický le = 4 <= 4 meňak logický le2 = 4 <= 3 meňak logický le3 = 3 <= 4 meňak logický g = 4 > 4 meňak logický g2 = 4 > 3 meňak logický g3 = 3 > 4 meňak logický l = 4 < 4 meňak logický l2 = 4 < 3 meňak logický l3 = 3 < 4 meňak logický e = 4 == 4 meňak logický e3 = 4 == 4.0 meňak logický l4 = 4 < 4.1 |
Logical operations
There are 3 supported logic values in Šaral. They are equivalent to Kleene logic –
pravda
(true
), ošaľ
(false
), skoroošaľ
(undefined
)
There are 3 corresponding logic operations
ne
– negationa
– operationand
abo
– operationor
These tables show all combinations of operations and values with their results
ne
operation
a | ne a |
---|---|
ošaľ | pravda |
skoroošaľ | skoroošaľ |
pravda | ošaľ |
Operation abo
abo | ošaľ | skoroošaľ | pravda |
---|---|---|---|
ošaľ | ošaľ | skoroošaľ | pravda |
skoroošaľ | skoroošaľ | skoroošaľ | pravda |
pravda | pravda | pravda | pravda |
Operation a
a | ošaľ | skoroošaľ | pravda |
---|---|---|---|
ošaľ | ošaľ | ošaľ | ošaľ |
skoroošaľ | oošaľ | skoroošaľ | skoroošaľ |
pravda | ošaľ | skoroošaľ | pravda |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
meňak logický p = pravda meňak logický o = ošaľ meňak logický so = skoroošaľ ciskaj p ciskaj o ciskaj so meňak logický pap = p a p meňak logický pao = p a o meňak logický paso = p a so meňak logický oap = o a p meňak logický oao = o a o meňak logický oaso = o a so meňak logický soap = so a p meňak logický soao = so a o meňak logický soaso = so a so ciskaj pap // pravda ciskaj pao // ošaľ ciskaj paso // skoroošaľ ciskaj oap // ošaľ ciskaj oao // ošaľ ciskaj oaso // ošaľ ciskaj soap // skorošaľ ciskaj soao // ošaľ ciskaj soaso // skoroošaľ meňak logický pabop = p abo p meňak logický paboo = p abo o meňak logický paboso = p abo so meňak logický oabop = o abo p meňak logický oaboo = o abo o meňak logický oaboso = o abo so meňak logický soabop = so abo p meňak logický soaboo = so abo o meňak logický soaboso = so abo so ciskaj pabop // pravda ciskaj paboo // pravda ciskaj paboso // pravda ciskaj oabop // pravda ciskaj oaboo // ošaľ ciskaj oaboso // skoroošaľ ciskaj soabop // pravda ciskaj soaboo // skoroošaľ ciskaj soaboso // skoroošaľ meňak logický nep = ne p meňak logický neo = ne o meňak logický neso = ne so ciskaj nep // ošaľ ciskaj neo // pravda ciskaj neso // skoroošaľ |
Procedures
Do we repeat same code? No problem, we have procedures.
1 2 3 |
bar iDoSomething() meňak neskutočné numeralio three = 3 ciskaj three |
With bar
, we declare procedure with name iDoSomething
. It is without parameters.
We can add parameters. They need to be in supported data types and array.
1 2 |
bar iDoSomethingElse(neskutočné numeralio x) ciskaj x |
We call the procedure with paľ do baru
.
1 2 3 4 |
paľ do baru iDoSomething() meňak neskutočné numeralio five = 5 paľ do baru iDoSomethingElse(five) |
Functions
Do we repeat same code? Do we want to return a calculated value? We have functions. Value is returned with vrac
, which have to be on last line of the function.
1 2 3 |
bar neskutočné numeralio returnSomething() meňak neskutočné numeralio five = 5 vrac five |
Function arguments are supported in all data types and arrays.
1 2 |
bar slovo returnString(slovo x) vrac x |
We call the function with vrac mi z baru
1 2 3 4 |
vrac mi z baru returnSomething() meňak slovo hello = "hello" vrac mi z baru returnString(hello) |
Be aware, that you have to initialize every function argument to a value. The same principle holds for procedures
1 2 |
meňak slovo word vrac mi z baru vracimSlovo(word) // error, meňak word is not initialized |
Conditional statements
Šaral language support conditional code execution as other problem-oriented programming languages, so called if-then-else
. In Šaral terminology keď-potom-inak
1 2 3 4 |
keď 1 > 0 potom paľ do baru iDoSomething() inak paľ do baru iDoSomethingElse(five) |
The inak
part is optionial
1 2 3 |
keď 2 > 0 potom meňak neskutočné numeralio two = 2 ciskaj two |
For-loops
One can execute a part of the code with defined range with zrob s meňakom <variable> od <value/variable> do <value/variable>
(so called. for-loop). The upper bound is always included.
1 2 |
zrob s meňakom x od 4 do 10 ciskaj x |
or
1 2 3 4 |
meňak neskutočné numeralio l = 4 meňak neskutočné numeralio u = 10 zrob s meňakom x od l do u ciskaj x |
Decremented for loop is possible as well
1 2 3 |
zrob s meňakom y od 10 do 1 meňak neskutočné numeralio x = y * y ciskaj x |
While loops
Loops with conditional execution (while-loops) are created with following construct. The loop is executed only when the loop condition has pravda
value.
1 2 3 4 |
meňak neskutočné numeralio x = 4 kým x <= 10 rob ciskaj x x = x + 1 |
1 2 3 4 5 |
meňak neskutočné numeralio y = 1 kým y <= 10 rob meňak neskutočné numeralio z = y * y ciskaj z y = y + 1 |
We can combine blocks of code (loops and condition) within themselfs.
1 2 3 4 5 6 7 8 9 |
zrob s meňakom i od 1 do 10 keď i % 2 == 0 potom meňak neskutočné numeralio x = i kým x <= 10 rob ciskaj x x = x + 1 inak zrob s meňakom j od i do 10 ciskaj j |
1 2 3 4 |
zrob s meňakom y od 1 do 10 zrob s meňakom x od 1 do 10 meňak neskutočné numeralio z = y * x ciskaj z |
Reading from standard input (console)
In case we want to communicate with computer, we can use 2 commands sluchaj
or vežmi
to read input written in the console.
1 2 3 |
meňak neskutočné numeralio nn vežmi nn // sluchaj nn |
They behave based on the variable type, we want to read to:
neskutočné numeralio
, input is not allowed to contain character or to exceed maximum integer value [-263; 263-1].skutočné numeralio
, needs to be in decimal format. If the input is inneskutočné numeralio
format, it is autoamtically converted.logický
, the valuepravda
orskoroošaľ
is read only if there is"pravda"
or"skoroošaľ"
as an input, otherwiseošaľ
value is set.písmeno
, always reads 1st character regardless input length.slovo
, read without change.
Similar way we can read a value and assign it to an element of an array of corresponding type.
1 2 |
funduš neskutočné numeralio array[2] vežmi array[0] |
1 2 |
funduš slovo array2[2] vežmi array2[0] |
Falda
It is possible to include other .srl
files in current Šaral file, with keyword falda
. We could include it from current folder or the include
folder by default.
1 2 3 4 5 6 7 8 |
// falda "slova.srl" bar slovo returnA() meňak slovo value = "A" vrac value bar printA() meňak slovo value = "A" ciskaj value |
1 2 3 4 5 6 7 |
// include "falda" and call one of the procedures meňak neskutočné numeralio five=5 ciskaj five falda slova paľ do baru printA() |
See also
The beginning
Language Specification
Recursion in Šaral programming language