An expression can be defined as a sequence of operands and operators (ECMA-334, 2006). In Modo syntax, expressions are used for the definition of elements and member elements.
Following is the Extended BNF notation of the expression in Modo syntax:
expression = {blank},
{start group symbol},
{blank},
operand | expression,
{
{blank},
operator,
{blank},
{start group symbol},
{blank},
operand | expression,
{blank},
{end group symbol},
},
{blank},
{end group symbol};
The expression definition above shows that expressions start with optional start group symbol, "(". An operand or expression follows this symbol. Then optional operator and operand/expression follow. Finally expression syntax ends with optional end group symbol, ")".
As mentioned in expression syntax, expressions are composed of operands and operators. Operators specify the operations that will be applied to the operands (ECMA-334, 2006).
In Modo syntax, there are two types of operators:
Following is the Extended BNF notation of unary operator and operator (Binary operator) in Modo syntax:
unary operator = "+" | "-" | "!" | "~"
| increment operator
| decrement operator;
operator = "*" | "/" | "%" | "+" | "-" | "<<" | ">>" | "<"
| ">" | "<=" | ">=" | "==" | "!=" | "&" | "^" | "|"
| "&&" | "||";
Expressions are evaluated from left to right. Operator precedence is the key factor that determines which operations will be applied to which operands.
Following table lists the precedence of the operators:
| Operator Precedence | ||
|---|---|---|
| Category | Operators | |
| 1 | Unary operators | + - ! ~ ++ -- |
| 2 | Multiplication operators | * / % |
| 3 | Addition operators | + - |
| 4 | Shifting operators | << >> |
| 5 | Relational operators | < > <= => |
| 6 | Equality operators | == != |
| 7 | Logical AND operator | & |
| 8 | Logical XOR operator | ^ |
| 9 | Logical OR operator | | |
| 10 | Conditional AND operator | && |
| 11 | Conditional OR operator | || |
First column specifies the priority of the operator. Unary operators have the highest priority (1) and conditional OR operator has the lowest (11) one. Second column specifies the category of the operator. Finally, third column lists the operators.
Unary operators have the highest priority. These operators consist of:
Multiplication operators have second highest priority. Multiplication operators consist of:
Addition operators consist of:
"<<" and ">>" symbols are used for bit shifting operations. Shifting operators consists of:
"<", ">", "<=" ve ">=" symbols are used for relational operations. Relational operators consist of:
"==" and "!=" operators are used for equality operations. Equality operators consists of:
Logical AND operator is used to form an operation like A & B. This operation results the bitwise logical AND of the operands A and B.
Logical XOR operator is used to form an operation like A ^ B. This operation results the bitwise logical exclusive OR of the operands A and B.
Logical OR operator is used to form an operation like A | B. This operation results the bitwise logical OR of the operands A and B.
Conditional AND operator is used to form an operation like A && B. This operation results the coditional AND of the operands A and B.
Conditional OR operator is used to form an operation like A || B. This operation results the conditional OR of the operands A and B.
Constant numeric values and strings can be used as operands in expressions.
Following is the Extended BNF notation of constant and string in Modo syntax:
constant = integer,
[
dot symbol,
{digit}-
];
The constant definition above shows that only the numeric values are considered as constants. A constant can be integer or real number. Decimal part of the number starts with dot symbol ".". Just like integer and real number which are numeric constants, string is the alphanumeric constant.
string = (
single quote symbol,
single quote escaped string,
single quote symbol
)
|
(
double quote symbol,
double quote escaped string,
double quote symbol
);
The string definition above shows that strings can start with single quote symbol ' or double quote symbol ".
Warning: If a string starts with single quote symbol, it must end with single quote symbol. In addition, if a string starts with double quote symbol, it must end with double quote symbol.
Elements and member elements can be considered as operands in Modo expressions.
For further information about elements and member elements, please refer to Using elements.
Unlike C, C++, C#, Java etc., function and/or method definition is not allowed in Modo syntax. Modo represents and forms the system and its states for the given time periods and for the given set of rules. Nevertheless, there can be built-in elements, functions and member methods defined in Modo language references specific for certain generators/compilers/interpreters. These built-in elements, functions and member methods can also be considered as operands in Modo expressions.