Arithmetic Expression

The type of an arithmetic operator is the type of the expression that contains it. Operands are automatically coerced to the type of the operator.

In this example the variables are named for their type. The type of the expression on the right hand side is determined by the type of the assignment variable; which is a cell. The Byte and Double values are implicitly coerced to a Cell. In this case the Byte value is sign extended to a Cell.

   Cell = Byte * (Cell + Double)

In languages in which operators derive their type from their operands, a set of rules is needed to determine what to do when operand types do not match. In Gilda there is no ambiguity and no rules are required. As you read an expression it is easy to figure out type coercions. In practice it also turns out that fewer explicit type casts are needed.

Expressions may be nested within matched pairs of parenthesis; which can be "()", "[]" or "{}" characters; your choice. The only String operator is concatenation for which an exclamation point ("!") is used. Real arithmetic operations are always signed.

       Operator                 Description                    Precedence

                 ~  E      Signed unary complement                 1
     +  E        -  E      Signed unary plus and minus             1
               E ^  E      Signed exponentiation                   2
               E |^ E      Unsigned integer exponentiation         2
   E *  E      E /  E      Signed Multiplication and division      3
               E %  E      Unsigned integer or IEEE remainder.     3
   E |* E      E |/ E      Unsigned multiplication and division    3
   E \\ E      E // E      Logical shift left and right            3
   E << E      E >> E      Circular shift left and right           3
   E +  E      E -  E      Signed addition and subtraction         4
               E /\ E      Logical And                             5
   E \/ E      E -- E      Logical Or and Exclusive Or             6

Since integer variables can be either signed or unsigned, three explicit unsigned operators augment their counterparts:

   |*   |/   |^

Overall this is less complex and you don't need to reference the type declaration to see that the operation is unsigned.

Arithmetic expressions and conditions are pure in that they have no side effects. They only read memory and can not perform I/O operations or raise exceptions. Like anything else they can raise faults such as division by zero. This distinction is discussed further in the section on Exceptions.

Array Variable

Conditional Expression