-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the riddle wiki!
The following is the specification of our language.
var length : integer is 3 // [example 1]
var a is true; // [example 2]
var b is 4.3 // [example 3]
- semicolons at the end of line are not mandatory
- the type is not mandatory if an initial value is specified
- variable name could start only with latin letters (upper or lower), the next chars could me latine letters, digits or '_' symbol
- only single line comments available in the language e.g
// comment
var a is true; // [example 2]
Type is one of the following list or identifier([TBD])
-
integer
- both positive and negative -
real
- both positive and negative -
boolean
-true
andfalse
Integers and real numbers are stored using 64 bits, akin to the long long
and double
in C++.
- Record
- Array
The assignment in case of user-defined variable works like assignment by reference
Is a kind of structure
, where record can be of any type.
type MyRecordType is record
var x0 : real
var y0 : real
var selected: boolean
end
Members are accessed with the dot notation
var dot: MyRecordType;
dot.x0 := 0.3;
dot.y0 := 6.4;
dot.selected := false;
Arrays in our language are indexed from 1
The length parameter (specified between brackets) is required except in routine parameters. It must be a compile-time constant. It can be read using the dot notation with the property length
.
Simple array:
type MyArray is array [ 4 ] integer;
var myArray : MyArray;
myArray[2] := 3;
myArray[1] := myArray.length
2D array:
type Array1D is array [ 4 ] integer;
type Array2D is array [ 4 ] Array1D;
var myArray : Array2D;
myArray[3][2] := 3;
[TBD] The element index is specified dynamically (using the syntax of expression). This allows organizing array processing in loops.
- Assignment
- Routine Call
- While loop
- For loop
- If statement
Assignment evaluates the value of the expression specified in the right part of the statement and copies it to the variable whose name is specified in the left part.
var a is 3;
a := a + 4;
Type of the variable from the left side should conform the type of the expression.
Only in case of user-defined types works like assignment by reference
Remember that a routine call makes an assignment of arguments
routine myFunction(a: integer, b:integer) : integer
is
return a + b;
end
var a is 1;
while a < 100 loop
a := a + 1;
end
The looping varibale should always be an integer and should be declared in the loop
Assignments to the loop variable are forbidden
var length : integer is 100;
type myArray is array [ length ] integer;
var array : myArray;
for a in reverse 1..100 loop
array[a] := a
end
for b in 1..100 loop
array[b] := 50 - b
end
1..100
notation is named Range
var a is true
var b is false
var c : integer
if b then
c := 3
else
c := 5
if a then
c := 4
end
end
// c is 4
integer |
real |
boolean |
true |
false |
is |
var |
record |
end |
type |
array |
while |
loop |
reverse |
for |
in |
if |
then |
else |
routine |
and |
or |
xor |
return |
not |
Left part | Right part | Semantics |
---|---|---|
integer | integer | direct value copying |
integer | real | copying with rounding to nearest integer |
integer | boolean |
true is converted to integer 1 false is converted to integer 0 |
real | real | direct value copying |
real | integer | integer is generalized to real |
real | boolean |
true is converted to real 1.0 ,false – to real 0.0
|
boolean | boolean | direct value copying |
boolean | integer | if integer is 1 , it is converted to true , if it is 0 , it’s converted to false ; otherwise, assignment is treated as erroneous. |
boolean | real | assignment is illegal |
Example:
// initialization
var a : integer is 2;
var b : real is 0.6;
var c : boolean is false;
// integer
a := b // a is now 1
a := c // a is now 0
a := 2 // a is now 2
// real
b := a // b is now 2.0
b := c // b is now false
b := 1.2 // b is nw 1.2
// boolean
c := a // error
c := 1 // c is now true
c := b // error
c := true // c is now true
User-defined types are considered as “reference types”. This means that a variable of a user-defined type is actually the reference to an object of the type. So, the variable serves as a “representative” of the object. Therefore, any assignment to a variable of an array or record type means copying the reference to the aggregate but not copying of the aggregate itself.