Šaral - Šariš Algorithmic Language

Š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.

Then run compiled program.

Program

It is for JVM, but you do not need to have classes. We declare few variables with meňak and print them to the console with ciskaj.

Second option to print something to the console is to use povidz. It is equivalent to ciskaj.

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

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.

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).

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.

Saral 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.

Operations

Arithmetic operations

There are supported mathematical operation between integers and floats (type neskutočné numeralio, skutočné numeralio) with precedence of parentheses and operations.

  • multiplication *
  • division / or :
  • addition +
  • substraction -
  • remainder (modulo) % (only for type neskutočné numeralio)
  • negation - (unary minus)

String concatenation

+ operation has a second meaning in Šaral language - string concatenation (slovo type).

It is enough, that one of both expression is type of slovo.

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.

Logical operations

There are 3 supported logic values in Saral. They are equivalent to Kleene logic -
pravda (true), ošaľ (false), skoroošaľ (undefined)

There are 3 corresponding logic operations

  • ne - negation
  • a - operation and
  • abo - operation or

These tables show all combinations of operations and values with their results

ne operation
ane a
ošaľpravda
skoroošaľskoroošaľ
pravdaošaľ
Operation abo
aboošaľskoroošaľpravda
ošaľošaľskoroošaľpravda
skoroošaľskoroošaľskoroošaľpravda
pravdapravdapravdapravda
Operation a
aošaľskoroošaľpravda
ošaľošaľošaľošaľ
skoroošaľoošaľskoroošaľskoroošaľ
pravdaošaľskoroošaľpravda

Procedures

Do we repeat same code? No problem, we have procedures.

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.

We call the procedure with paľ do baru.

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.

Function arguments are supported in all data types and arrays.

We call the function with vrac mi z baru

Be aware, that you have to initialize every function argument to a value. The same principle holds for procedures

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

The inak part is optionial

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.

or

Decremented for loop is possible as well

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.

We can combine blocks of code (loops and condition) within themselfs.

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.

They behave based on the variable type, we want to read to:

  • neskutočné numeralio, input is not allowed to contain charakter or to exceed maximum integer value [-263; 263-1].
  • skutočné numeralio, needs to be in decimal format. If the input is in neskutočné numeralio format, it is autoamtically converted.
  • logický, the value pravda or skoroošaľ is read only if there is "pravda" or "skoroošaľ" as an input, otherwise oš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.

See also

The beginning
Language Specification