driver hello:
import
con := $lib.console;
routine main:
process
con.print ("Hello World!");
return;
In this article you will learn about:
Next code represents a very symple program written in EVE language:
# Progra example written in EVE
driver main(Integer p1, p2): //script name
** use a system library
import
con := $lib.console;
** define two functions
function
Integer add(Integer p1, p2) => (p1+p2);
Integer sub(Integer p1, p2) => (p1-p2);
** define executable region
process
con.print ("param1:#p1, #p2");
v1 := add(p1, p2);
v2 := sub(p1, p2);
con.print ("result: #v1");
con.print ("result: #v2");
return;
# comments in EVE language
*******************************
** old style boxed comments **
*******************************
driver test:
# Main routine: ( this is title)
routine main:
Integer a = 0;
process
** Next we use expression comment:
a := a + 1 /* *(a - 1) */ -1;
return;
end driver. // end of module
The name of identifiers in EVE can have a length of 30 characters. A name starts with lowercase letters (a..z) or capital letters (A..Z) followed by one or more characters or numbers. No special characters or spaces are permitted in the name except underscore ("_"). A variable can contain underscore and can start with underscore but it can not end with underscore and can not use two consecutive underscore.
These are valid identifiers
x, y, z
a1,a2,a3
thisIsOK
this_is_ok
_this_is_valid
These are invalid identifiers
1st
not_valid\_
\_not_valid\_
Prefix EVE is using following sigils to define variables:
* | variable arguments |
$ | define global constant |
@ | define global variable |
. | define public variable |
_ | define private variable |
none | define scope variable |
A variable is represented by an identifier, and is pair-up with a data type using ":". Variables are abstract concepts representing primitive values or references to memory locations. Variables can be modified during the program execution using modifiers like: { :=, ::, +=, -= ... }.
patterns:
** define alias for a:
** alias names have to start with uppercase letters.
type Type_name := super_type {parameters};
** shared variables
global
** use type to define a variable
Type_name: var_name;
** with specific value and type
Type_name: var_name = value;
** multiple variables in one assignment
Type_name: var_name1, name2 ...= value;
** multiple variables with diverse values
Type_name: var_name1=value1, var_name2 = value2;
global
** two integer numbers
Integer a = 0;
Integer b = 1;
** multiple Double numbers
Double d = 2.5;
Double x,y,z = 0.0;
zero value When a variable is specified, and the initializer ":=" is missing the variable takes default zero value. This value is different for each data type. For example zero value for Integers = 0 for Double = 0.0 and for String = ''.
Assign value can be done using operator: ":=". But this operator has a strange behavior that you must understand to avoid unintended side-effects. It transfer a value "by sharing". It transfers a memory location not the underline value:
identifier := variable_name; // share a reference to variable
identifier := function_name; // share a reference to function
identifier := literal; // mutate value / initialize
identifier := expression; // mutate value / initialize
identifier := function_name(); // mutate value / reset value
clone:
To make a clone/copy underline value from a reference you must use clone operator that is (::). This will transfer a value not a reference. After clonning, we can modify one value without affecting the other.
// making a clone
variable_name :: reference_name;
variable | Description |
---|---|
@object | current instance of a class, current object |
@result | default result of a routine when a name is not specified |
@error | current exception object of type Exception |
Expressions are created using identifiers, operators, functions and constant literals.
** simple expressions in print statement
print 10;
write "this is a test";
** complex expressions can use ()
print (10 + 10 + 15); // numeric expression
print (10 > 5) or (2 < 3); // logical expression
** list of expressions are enclosed in ()
print (1, 2, 3); // expect: 1 2 3
print (10, 11, 12); // expect: 10 11 12
** using write to: avoid new line and print
write (1,2);
write (3,4);
** now create a new line and output the text
print; // 1234
A ternary operator is "if". It can be used with conditional expressions to return one value or other using a list of conditional expressions separated by comma called nodes.
variable := (value1 if condition else value2); variable := (value1 if condition1 else value 2 if condition2 else value3);
variable test = True; expect(True if test else False); // will pass
One statement can be declarative or imperative.
The most simple statements are definitly the declaration statements:
** declare two numbers
Integer a := 0;
Double b := 1.5;
** verification statement
expect (a == 0, b == 1.5);
end;
One expression can span multiple lines.
** demo for multiple lines
routine main:
Integer x;
Hash a;
process
** multi-row expression
x := 1 +
2 +
(3 + 4)
+ 5;
** multi-row literal
a := {
(1:2),
(3:4),
(5:6)
};
return;
Computer was invented in England during WW2 so, we prefer English words even though a computer language could be created using keywords from other spoken languages. EVE is using about 50 English reserved words. You can not use these words as identifiers.
abort | alias | alter | analyze |
append | apply | ascending | augment |
begin | break | by | |
case | class | clone | close |
commit | constant | create | cursor |
defer | delete | descendin | discard |
else | end | error | exit |
expect | fail | feature | fetch |
for | from | function | group |
if | import | inherit | |
insert | into | item | join |
limit | loop | method | object |
offset | open | order | orif |
over | package | pass | |
process | raise | read | record |
recover | release | remove | repeat |
reset | rest | result | resume |
retry | return | rollback | routine |
solve | select | resolve | skip |
step | store | switch | task |
then | trial | try | type |
update | use | variable | view |
where | while | with | write |
Keyword | Description |
---|---|
import | define import region |
type | define data-type or sub-type |
constant | declare module constants (start with "." if is public) |
variable | declare module variables (start with "." if is public) |
function | start a declaration region for named expression |
Keyword | Description |
---|---|
module | define a program file (module-name = file-name) |
class | define a composite data type for object oriented programming |
create | begin constructor region for a classes |
remove | define object disposal region, executed when object is out of scope |
feature | define a design pattern that can be enabled by a class |
augment | define an augment for an existing class |
routine | define a named block of code belonging to a module |
method | define a named block of code belonging to a class |
process | begin executable region for a routine and constructor for a class |
recover | define a recover region for methods |
release | define a finalization region for routines |
return | terminate a routine/function or a class declaration |
Keyword | Description |
---|---|
local | create a local block of code |
if | conditional operator |
else | alternative path for { when, case, while } statements |
switch | multi-path case (variable) selector |
case | define a pathway in multi-case methods |
loop | unconditional repetitive block |
while | conditional repetition block |
for | visitor iteration loop |
end | block finalization keyword |
with | define local scope/ establish qualifier suppression block for records |
Keyword | Description |
---|---|
is | check data type x is Null | quest associated keyword |
in | check data type x is Null | quest associated keyword |
not | logical NOT operator |
and | logical AND operator |
or | logical OR operator |
xor | logical XOR operator |
Keyword | Description |
---|---|
exit | silent stop a routine and return control to the caller |
abort | stop driver with negative error code (unrecoverable error) |
over | stop current process and then execute: release & report |
raise | create exception with error code > 0 (recoverable) |
break | early terminate execution of a repetitive block |
repeat | jump over all other statements to the end of block |
fail | create standard work-flow error if condition is true |
pass | create standard unexpected error if condition is true |
retry | work-flow jump backwards to specified step |
apply | start subroutine execution in syncrhonous mode |
begin | start subroutine execution in asyncrhonous mode |
solve | execute one aspect in synchronous mode |
defer | start execution for one aspect in asynchronous mode |
yield | interrupt current execution and wait for deferred processes |
resume | used in work-flow handlers to continue with next step |
EVE us ASCII symbols for operators. One operator can be single character or two characters with no space between tem. Sometimes we use the same character twice for example "==" or ">>". This technique is known in many other computer languages.
Single symbol:
# , : . ; = ~ ? % ^ * - + / < > ~ & | ^ ! @ $
Two symbols:
** // == != =+ <> << >> => >= <= <: .. .! !. !!
Modifiers:
++ -- :: := += -= *= /= %= ^= &= |= <+ +>
Delimiters:
"_" '_' `_` (...) [...] {...} #(...)
EVE use al single simbols usually found on your keyboward.
Symbol | Description |
---|---|
! | Negation symbol |
? | String template find & replace |
# | Comment (title) at beggining of line (not indented) |
$ | Platform (environment) variable prefix |
@ | System variable prefix |
; | Statement separator | End of statement |
: | Define subroutine, class or block | Pair-up/binding operator (a:b) |
= | Setup initial value for variables or parameters |
~ | Check if two variables have same type |
. | Decimal separator | Prefix public member | Member qualifier |
, | Enumeration for elements | complex expression |
* | Variable arguments | Multiplication |
| | Used in set builders | Set union "∪" |
& | String concatenation | Set intersection "∩" |
Eve use two symbols to create supplementary operators.
Symbol | Description |
---|---|
** | Single line comment |
// | End of line comment |
.. | Domain (n..m) or slice [n..m] |
.! | Domain exclude upper limit |
!. | Domain exclude lower limit |
!! | Domain exclude both limits |
=+ | Outer join operator used in data "select" statement |
<: | Define sub-type for a class or super-type |
:> | Numeric data conversion or convert a subtype into a supertipe. |
<+ | Append to the end of a collection |
+> | Append to the beginning of a collection |
<< | Shift ordered collection to left with n: X := C << n |
>> | Shift ordered collection to right with n: Y := C >> n |
:= | Assign value of expression to a variable. |
In the syntax description "..." represent content and "_,_,_," represents a sequence of elements. In descriptions vertical bar "|" represents second alternative. Some operators can have multiple purposes depending on the context and data types.
Symbol | Description |
---|---|
**...** | Block comments | Header comments |
/*...*/ | Outline comments | Expression comments |
(_,_,_) | Expression | Tuple literal |
[_,_,_] | Range | Index | List literals |
{_,_,_} | Ordinal type | Set of values | Hash type | Generic types |
#(....) | String interpolation (placeholder) for operator "?" |
Symbol | Description |
---|---|
`x` | Single symbol: ASCII |
'x' | Limited capacity ASCII string |
"x" | Variable capacity string: UTF8 |
Symbol | Description |
---|---|
+ | Concatenate two strings after trimming first string |
/ | Concatenate two strings with "/" separator and de-duplicate "//" |
\ | Concatenate two strings with "\" separator and de-duplicate "\\" |
Symbol | Description |
---|---|
* | Numeric multiplication | Scalar operator |
/ | Numeric division |
% | Reminder operator | Scalar operator |
+ | Numeric addition | String concatenation | Set union |
- | Numeric subtraction | String concatenation | Set difference |
EVE use two symbols to create a additional operators.
Symbol | Description |
---|---|
== | Equal | deep comparison |
!= | Different value | (deep comparison) |
> | Greater than value |
< | Less than value |
>= | Greater than or equal to values |
<= | Less than or equal to values |
Each modifier is created with pattern "x=" where x is a single symbol:
symbol | meaning |
---|---|
:= | Assign by reference | shallow assignment |
:: | Assign by copy | clone assignment |
+= | Increment value |
-= | Decrement value |
*= | Multiplication modifier |
/= | Real division modifier |
%= | Modulo modifier |
In following table: A, B, C are collections and x is a member:
Operator | Result | Description |
---|---|---|
A | B | set | Union A with B: "∪" use like C : = A | B (return a new set) |
A & B | set | Intersect A with B: "∩" use like C := A & B (return a new set) |
A - B | set | Simple difference, use like C := A - B (return a new set) |
A -- B | set | Symmetric difference, use like C := A -- B (return a new set) |
A ++ B | list | Concatenate two lists use like L := A ++ B (return a new list) |
A <= B | logic | verify if A is subset of B: In math: ⊂ |
A >= B | logic | verify if B is subset of A: In math: ⊃ |
C <+ x | list | append element x to C at the end |
C +> x | list | append element x to C at the beginning |
These operators are expected logical values T = True, F = False
Symbol | Description |
---|---|
if | conditional operator |
is | check element is of Type or same reference (object) |
is not | check element is not of Type or different references (objects) |
in | logic belong to: instead of "∈" |
not in | logic not belong to: instead of "!∈" |
not | logic NOT (negation) |
and | logic AND (intersection) |
or | logic OR (union) |
xor | logic Exclusive OR |
Table of truth for logical operators:
A | B | A and B | A or B | A xor B |
---|---|---|---|---|
True | True | True | True | False |
True | False | False | True | True |
False | True | False | True | True |
False | False | False | False | False |
These operators are working for natural numbers ≥ 0
symbol | description |
---|---|
~ | bitwise NOT (unary) |
& | bitwise AND |
| | bitwise OR |
^ | bitwise XOR |
<< | shift bits to left |
>> | shift bits to right |
Binary operators
A | B | A & B | A | B | A ^ B |
---|---|---|---|---|
00 | 00 | 00 | 00 | 00 |
01 | 00 | 00 | 01 | 01 |
11 | 01 | 01 | 11 | 10 |
10 | 11 | 10 | 11 | 01 |
11 | 11 | 11 | 11 | 00 |
Unary operators
A | ~A | A << 1 | A >> 1 |
---|---|---|---|
0000 | 1111 | 0000 | 0000 |
1111 | 0000 | 1110 | 0111 |
0111 | 1000 | 1110 | 0011 |
0110 | 1001 | 1100 | 0011 |
Read next: Structure