There are several types of operators in the evolve language these include bitwise, arithmetic and relational operators.
The arithmetic operators are very similar to those in other programming languages. The philosophy behind evolve was to make the code readable and to avoid errors to this end only one arithmetic operator is allowed on a line.
The following code demonstrates the arithmetic operators
//---------------------------------------
// File: ArithmeticOperators.e
//---------------------------------------
//---------------------------------------
// Block: go
//---------------------------------------
block Go
A = 2.3 * 2
outl "2.3 * 2 = " A
A = 2.3 / 2
outl "2.3 / 2 = " A
A = 205 % 2
outl "205 % 2 = " A
A = 2.3 + 2
outl "2.3 + 2 = " A
A = 2.3 - 2
outl "2.3 - 2 = " A
_block
The relational operator abbreviations are very similar to those in other programming languages. Relational operators evaluate the relationship between two expressions and gives a true or false response.
The following code demonstrates the relational operators
//---------------------------------------
// File: RelationalOperators.e
//---------------------------------------
//---------------------------------------
// Block: go
//---------------------------------------
block Go
Answer = 3 < 5
outl "3 < 5 = " Answer
Answer = 3.78 <= 2.78
outl "3.78 <= 2.78 = " Answer
Answer = 3 > 5
outl "3 > 5 = " Answer
Answer = 3.78 >= 2.78
outl "3.78 >= 2.78 = " Answer
Answer = "test" == "test"
outl ""test" == "test" = " Answer
Answer = 'a' != 'b'
outl "'a' != 'b' = " Answer
_block
The arithmetic operators are very similar to those in other programming languages. They simply increment or decrement the variable by 1.
++
--
Description
Increment
Decrement
The following code demonstrates the increment and decrement operators
//---------------------------------------
// File: IncDecOperators.e
//---------------------------------------
//---------------------------------------
// Block: go
//---------------------------------------
block Go
I = 0
J = 10
while I < 10
outl I " " J
++ I
-- J
_while
_blockck
The bitwise operator manipulates bits in variables, these bits are often used when in programs that interact with hardware. The philosophy behind evolve was to make the code readable and to avoid errors to this end only one bitwise operator is allowed on a line.
The ones_complement operator acts only on one value this operator changes every bit that is set to 0 and every bit that is set to 0 to 1.
The not operator acts only on one value this operator changes will change a variable from true to false or false to true.
The shift_left and shift_right operators shift the bits in the left operand by the number of bits in the right operand either to the left or right.
The and_bitwise operator sets the bit to 1 if both the corresponding bits are 1 in all other cases the bit will be set to zero.
The or_bitwise operator sets the bit to 1 if either of the corresponding bits are 1 in all other cases the bit will be set to zero.
The xor_bitwise sets a bit to 1 if the corresponding bits are different in all other cases the bit will be set to zero.
The following example shows the bitwise operators in use
//---------------------------------------
// File: BitwiseOperators.e
//---------------------------------------
//---------------------------------------
// Block: go
//---------------------------------------
block Go
A = 0x06
B = 0x02
Answer = A | B
outl "A | B = " Answer
Answer = A & B
outl "A & B = " Answer
Answer = A ^ B
outl "A ^ B = " Answer
Answer = B >> 1
outl "B >> 1 = " Answer
Answer = B << 2
outl "B << 2 = " Answer
Answer = ! B
outl "! B = " Answer
Answer = ! Answer
outl "! Answer = " Answer
Answer = ~ A
outl "~ A = " Answer
_block
The and_logic and or_logic operator are used to to combine logical tests within a conditional statement.
&&
||
Description
Logical AND
Logical OR
If the and_logic operator is used then the logical tests must both evaluate to true, if the or_logic operator is used then either of the logical tests can evaluate to true.
The following code shows an example of logical operators.
//---------------------------------------
// File: LogicalOperators.e
//---------------------------------------
//---------------------------------------
// File: LogicalOperators.e
//---------------------------------------
//---------------------------------------
// Block: go
//---------------------------------------
block Go
A = 6786
B = "Hello"
if A == 6786 && B == "Hello"
outl "A == 6786 && B == "Hello""
_if
if A == 6786 && B == "Bye"
//this should not get printed
outl "A == 6786 && B == "Bye""
_if
if A == 6786 || B == "Bye"
outl "A == 6786 || B == "Bye""
_if
_block