A expression is a combination of keywords, operators, variables, and constants that yields a string, number, or object. An expression can be used to perform a calculation, manipulate characters, or test data. Expressions are made up of operators and operands. An operand is an entity on which an operator acts. Operands include constants, variables, strings, function calls, subscript expressions, member-selection expressions, and complex expressions formed by combining operands with operators or by enclosing operands in parentheses. Operators specify an evaluation to be performed on one (unary) or two (binary) operands. There are three types of operators:
A unary expression consists of either a unary operator followed by an operand as the following syntax shows: operator operand. For Example, sizeof or typeof keywords followed by an expression. The expression can be either the name of a variable or an expression.
A binary expression consists of two operands and an operator in between as the following syntax shows: operand1 operator operand2.
Operators follow a strict precedence which defines the evaluation order of expressions containing these operators. ATEasy operators are shown below in order of precedence from highest to lowest. Operators in the same level of precedence are calculated from left to right.
Operator |
Name |
Type, Order of Evaluation, Level |
Expressions Type |
Examples |
( ) |
Expression, Function |
Binary, Left to right, 1 |
|
(i+3)*2+abs(j) |
. (dot) |
Member, Scope resolution |
Binary, Left to right, 1 |
Object, Struct, Module, Library, Form |
Program.Tests(i), System.m_iState, btnOk.Caption, student.sName |
[ ] |
Subscript |
Binary, Left to right, 1 |
Array and Integer inside the [ ] |
aa[i, j], aa[i], sName[i] |
& |
Address Of |
Unary, N/A, 2 |
Unary, N/A, 10 |
dwDWord=&wWord |
- |
Arithmetic negation |
Unary, Right to Left, 3 |
Numeric |
-23, -j |
not |
Bitwise complement |
Unary, Right to Left, 3 |
Integer, Object, Bool, Procedure
|
not bOk, not ob, not proc |
descof |
Description string |
Unary, Right to Left, 3 |
Any expression |
descof proc_name, descof var_name |
nameof |
Name string |
Unary, Right to Left, 3 |
Any expression |
nameof var_name, nameof proc-name |
sizeof |
Size in bytes |
Unary, Right to Left, 3 |
Any expression |
sizeof aa[i], sizeof aa[i, j] |
typeof |
Type string |
Unary, Right to Left, 3 |
Any expression |
typeof i |
^ |
Power |
Binary, Right to left, 4 |
Numeric |
i ^ 3, d ^ 3.4 |
* |
Multiplication |
Binary, Left to right, 5 |
Numeric |
i*j, i*2.25 |
/ |
Floating point division |
Binary, Left to right, 5 |
Numeric |
d/3.14, d/2, i/3.4 |
div |
Integer division |
Binary, Left to right, 5 |
Integer |
i div 3 |
mod |
Integer remainder |
Binary, Left to right, 5 |
Integer |
i mod 3 |
+ |
Addition |
Binary, Left to right, 6 |
Numeric, String |
3+4 |
- |
Subtraction |
Binary, Left to right, 6 |
Numeric |
3-j, d-4.45, v-5.04 |
shl |
Integer left shift |
Binary, Left to right, 7 |
Integer |
i shl 4 |
shr |
Integer right shift |
Binary, Left to right, 7 |
Integer |
j shr i |
< |
Less than |
Binary, Left to right, 8 |
Numeric |
i<3, d<3.56, i<d, sName<"Ron" |
> |
Greater than |
Binary, Left to right, 8 |
Numeric |
j>d, sName>"Albert" |
<= |
Less than or equal to |
Binary, Left to right, 8 |
Numeric |
bsName<"Art", d<3.45 |
>= |
Greater than or equal to |
Binary, Left to right, 8 |
Numeric |
sName>="Su" |
= |
Equality |
Binary, Left to right, 8 |
Numeric |
s="Yanor" |
<> |
Inequality |
Binary, Left to right, 8 |
Numeric |
j<>i, s<>"Neil" |
and |
Bitwise AND |
Binary, Left to right, 9 |
Integer |
i and 0b101 |
or |
Bitwise inclusive OR |
Binary, Left to right, 9 |
Integer |
dwFlags or 0x20A |
xor |
Bitwise exclusive OR |
Binary, Left to right, 9 |
Integer |
dwFlags or 1 |
new
|
Create new COM or .NET Object |
Unary, Left to right, 10 |
COM or .NET Class Name |
obEvt= new AEvent dt=new MSCORLIB.DateTime(2005, 5, 5) |
= |
Assignment |
Binary, Left to right, 11 |
Any expression |
i=j, sName="abc"
|
Expressions are calculated according to the following rules of precedence:
An operand between two operators of different precedence is bound to the operator with higher precedence.
An operand between two equal operators is bound to the one on its left.
Expressions within parentheses are evaluated prior to being treated as a single operand.
Expressions can be of the following types:
Type |
Description |
bool-expr |
Any expression that evaluates to an boolean value of the Bool data type. Elements of an boolean expression can include a function that returns a boolean value, a boolean literal, a boolean constant (True or False), a boolean variable, a boolean Variant, or a function that returns a boolean Variant. bool-expr are the result of any of the comparison operators (e.g. '>='). See also Statements Optimize Short Circuit Boolean Expression. |
integer-expr |
Any expression that evaluates to an integer value of the following data types: Char, Byte, WChar, Short, Word, Long, DWord, String element (Char or WChar). Elements of an integer expression can include a function that returns an integer value, na integer literal, an integer constant, an integer variable, an integer Variant, or a function that returns an integer Variant. |
numeric-expr |
Any expression that evaluates to a floating point numeric value of the following data types: Float, Double, Currency and DateTime. Elements of a numeric expression can include a function that returns a numeric value, a numeric literal, a numeric constant, a numeric variable, a numeric Variant, or a function that returns a numeric Variant. |
string-expr |
Any expression that evaluates to a sequence of contiguous characters. Elements of a string expression can include a function that returns a string, a string literal, a string constant, a string variable, a string Variant, or a function that returns a string Variant. |
procedure-expr |
Any expression that evaluates to an object. Elements of an object can include a function that returns an object string, an object literal, an object constant (NoProcedure) or an object variable. |
object-expr |
Any expression that evaluates to an object. Elements of an object can include a function that returns an object string, an object literal, an object constant (Nothing), an object variable, an object Variant, or a function that returns an object Variant. |
Boolean, integer and numeric expression are automatically prompted by the compiler when necessary. The following rules may be use to determine when one expression type is promoted to another:
Operands that accept bool-expr also accept integer-expr.
Operands that accept numeric-expr also accept integer-expr and bool-expr.
Operands that accept integer-expr also accept bool-expr.
Operands that accept numeric-expr also accept integer-expr.
Data Types, Literals, Statements Optimize Short Circuit Boolean Expression