Modo, Easy Modeling Language

Documentation

Expressions

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, ")".

Operators

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:

  1. Unary operators take one operand (e.g. -A, A++).
  2. Binary operators take two operands (e.g. A + B).

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

Unary operators have the highest priority. These operators consist of:

  1. Unary plus operator is used to form an operation like +A. This operation results simply the value of the operand.
  2. Unary minus operator is used to form an operation like -A. This operation results the multiplication of the operand by (-1).
  3. Negation operator is used to form an operation like !A. This operation results the logical negative value of the operand.
  4. Bitwise complement operator is used to form an operation like ~A. This operation results the complement of the operand.
  5. Increment and decrement operators is used to form an operation like ++A, --A, A++ or A--. Increment operator (++A or A++) increases the operand value by one. Similarly decrement operator (--A or A--) decreases the operand value by one. Evaluating expressions from left to right can yield different results for ++A and A++. One must remember that, the operation ++A is calculated before the A++ operation.
Multiplication operators

Multiplication operators have second highest priority. Multiplication operators consist of:

  1. Multiplication operator is used to form an operation like A * B. This operation results the multiplication of the operand A by B.
  2. Division operator is used to form an operation like A / B. This operation results the division of the operand A by B.
  3. Remainder operator is used to form an operation like A % B. This operation results the remainder of the division of the operand A by B.
Addition operators

Addition operators consist of:

  1. Addition operator is used to form an operation like A + B. This operation results the addition of the operands A and B.
  2. Subtraction operator is used to form an operation like A - B. This operation results the subtraction of the operand B from A.
Shifting operators

"<<" and ">>" symbols are used for bit shifting operations. Shifting operators consists of:

  1. Left-shifting operator is used to form an operation like A << 5. The A << 5 operation yields the 5 bits left-shifted value of the operand A.
  2. Right-shifting operator is used to form an operation like A >> 5. The A >> 5 operation yields the 5 bits right-shifted value of the operand A.
Relational operators

"<", ">", "<=" ve ">=" symbols are used for relational operations. Relational operators consist of:

  1. "Less than" operator is used to form an operation like A < B. If the value of the operand A, is less than the value of the operand B, A < B operation yields the logical true value. If the value of the operand A, is greater than or equal to the value of the operand B, A < B operation yields the logical false value.
  2. "Greater than" operator is used to form an operation like A > B. If the value of the operand A, is greater than the value of the operand B, A > B operation yields the logical true value. If the value of the operand A, is less than or equal to the value of the operand B, A > B operation yields the logical false value.
  3. "Less than or equal to" operator is used to form an operation like A <= B. If the value of the operand A, is less than or equal to the value of the operand B, A <= B operation yields the logical true value. If the value of the operand A is greater than the value of the operand B, A <= B operation yields the logical false value.
  4. "Greater than or equal to" operator is used to form an operation like A >= B. If the value of the operand A is greater than or equal to the value of the operand B, A >= B operation yields the logical true value. If the value of the operand A is less than the value of the operand B, A >= B operation yields the logical false value.
Equality operators

"==" and "!=" operators are used for equality operations. Equality operators consists of:

  1. "Equal to" operator is used to form an operation like A == B. If the value of the operand A is equal to the value of the operand B, A == B operation yields the logical true value.
  2. "Not equal to" operator is used to form an operation like A != B. The A != B operation is logically negative to the operation A == B. If the value of the operand A is not equal to the value of the operand B, A != B operation yields the logical true value.
Logical AND operator

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

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

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

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

Conditional OR operator is used to form an operation like A || B. This operation results the conditional OR of the operands A and B.

Constants and strings

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

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.

Functions and member methods

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.