ŠARAL 2.0 – Language specification
Note: This is the English translation of the original specification document in Slovak.
My specification is based on a former Šaral presentation (Slovak).
Identifier are composed from lower and uppercase characters, digits and underscores. They can start with a letter or an underscore, such as
_?[:letter:]([:digit:][:letter:]_)*.
Key words
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 |
furt meňak parcela dimenzion pravda ošaľ skoroošaľ logický skutočné neskutočné numeralio písmeno slovo falda inakši bar paľ do baru vrac še z baru vrac stuj keď potom inak zrob s meňakom od do kým rob ciskaj vežmi sluchaj povidz a alebo ne |
Keywords dimenzion
a stuj
stay in Šaral 2.0 specification preserving backward compatibility with former Šaral specification.
Operators
1 2 3 4 5 |
+, -, *, /, :, % a, alebo, ne ==, <, >, <=, >=, <> = [] |
Data types
1 2 3 4 5 6 |
skutočné numeralio neskutočné numeralio logický písmeno slovo funduš |
First 4 types are considered as primitive, first 5 as basic, type funduš
as container type.
Trinary logic
Šaral uses Three-valued logic with these values pravda
, ošaľ
& skoroošaľ
. They represent True
, False
a Unknown
in Kleene’s logic. That means a condition is only true
if all statement have pravda
value.
Variable and constants declarations
1 2 |
<modifier> <type> <name> <modifier> <type> <name> = <value> |
<modifier>
means, either identifier <name>
is a variable (meňak
) or a constant (furt
). By declaring furt
it is required to initialize to some value.
Examples
1 2 3 4 5 6 |
furt skutočné numeralio pi = 3.14 furt neskutočné numeralio answer = 42 meňak logický big = ošaľ meňak slovo name meno = "Ladislav" meňak písmeno class = 'A' |
Array declarations
1 2 3 4 5 |
funduš <type> <name> [dimension] funduš <type> <name> [dimension] dimenzion funduš <type> <name> [dimension] dimenzion funduš <type> <name> [dimension] |
It is recommended to use first declaration with funduš
. Keyword dimenzion
is supported preserving backward compatibilty with first Šaral version. Array dimension
must be of type neskutočné numeralio
.
Examples
1 2 3 |
funduš skutočné numeralio šč [3] meňak neskutočné numeralio N = 42 dimenzion funduš logický fň [N] |
Procedures and functions
Šaral supports functions and procedures. Looking from higher perspective they appear to be like black boxes bar
(pub) – some things enter inside and sometimes something is returned outside.
1 2 3 4 |
bar <name>(<type> <name>, <type> <name>, ...) ... decription, what is going on in a pub ... |
1 2 3 4 5 |
bar <name>(<type> <name>, <type> <name>, ...) ... decription, what is going on in a pub ... vrac <value> |
First bar
does not return anything, second bar after finishing returns a value, which has the same type as bar
. If we want to call services of a pub bar
, we do it by calling paľ do baru
as a procedure or vrac mi z baru
as a function. As an input argument can be used meňak
of arbitrary type, bar
can only return arbitrary basic type. Input arguments are passed by reference.
External functions
We can call other bars
from external environments, which use different languages (types must be the same as in Šaral 2.0). If we want to taste an external bar
, we call it by word inakši
1 2 3 |
inakši bar <name>(<type> <name>, <type> <name>, ...) inakši <type> bar <name>(<type> <name>, <type> <name>, ...) |
Examples
1 |
inakši bar neskutočné numeralio puts(slovo s) |
1 2 3 4 |
bar ZámenaManželiek(neskutočné numeralio A, neskutočné numeralio B) A = A + B B = A - B A = A - B |
1 2 3 |
bar slovo SlovakPub() meňak slovo food = "Bryndzove halusky"; vrac jedlo |
1 2 |
meňak slovo halusky halusky = vrac mi z baru SlovakPub() |
1 2 3 |
meňak neskutočné numeralio X = 500 meňak neskutočné numeralio Y = 600 paľ do baru ZámenaManželiek(X, Y) |
Conditions
1 2 3 4 |
keď (furt | meňak) == (furt | meňak) potom ... inak ... |
1 2 3 4 |
keď (logický furt | meňak) potom ... inak ... |
The inak
part is not required.
Loops
We declare the for-loop like construct as:
1 2 |
zrob s meňakom <name> od (furt | meňak) do (furt | meňak) ... |
variables in loop are in interval <from;to)
While loop
1 2 |
kým (furt | meňak) == (furt | meňak) rob ... |
1 2 |
kým (logický furt | meňak) rob ... |
I/O
stdin/stdout
To print something on standard output we call ciskaj <name>
, where <name>
is a meňak
or furt
. To read from input we call vežmi <name>
, where <name>
is a meňak
, we want to read.
https://www.facebook.com/%C5%A0aral-433557560407/
Napr.:
Ošaľ- vyhodnocuje sa počas behu, za hodnotu konštanty alebo premennej je dosadená taká hodnota aby výraz získal hodnotu “Ne” ak je to možné.
Pretože vyhodnocovanie logického výrazu môže byť veľmi náročné, ak je prekročená zatiaľ nešpecifikovaná hranica-hĺbka vyhodnocovania, tak sa použije pravidlo “Ta boh nezna” a výraz získa hodnotu “Ne”.
Vďaka. To som si doteraz nevšimol. Zosychronizujeme sa s laciKE