Next: , Previous: , Up: Top   [Index]

5 Operators

Operators compute values and may have side effects. They are not different in this respect from functions.

Unlike function names, the operator names are not aime identifiers, but instead are composed of signs such as ‘+’ and ‘*’.

aime operators have one or two operands. The expression syntax has the one operand operators preceding their operand and the two operands operators appearing in between the operands, hence the prefix unary operator and infix binary operator terms.

Unary operators include the arithmetic negation ‘-’, the no operation ‘+’ and the logical negation ‘!’.

    +(a * 2)
    -(-b + 3)

Binary operators include the arithmetic ‘+’, ‘-’, ‘*’ and ‘/’, the assignment ‘=’, the comparison ‘<’ and ‘>’.

    1 + 2
    d * 4
    .5 / e + f
    g < h
    303 > 505
    i = i - 1

Like function parameters, the operands of an operator have a defined type. aime defines the ‘integer’ addition operator on two ‘integer’ operands and evaluating to an ‘integer’ value. Unlike for functions, there are no implicit convertions for operator operands. The aimeinteger’ on ‘integer’ addition operator does not add numbers of types other than ‘integer’. The name of operators are nonetheless not unique, and there are defined eight more operators adding numbers of the numerical intrinsic types (‘real’ with ‘real’, ‘integer’ with ‘real’, ‘real’ with ‘integer’, etc).

See The Intrinsic Types.

Operators associate a priority or precedence value that dictates the order in which they are applied. The ‘*’ multiplication operators have a precedence higher than that of the ‘+’ addition operators. In both

    a * b + c


    c + b * a

expressions, the multiplication of a and b occurs before the addition with c.

Parantheses change the order of operators application, with those inside applied before those outside. The

    (a + b) * c

expression has a and b added before their sum is multiplied by c.

Operators also define an associativity order that dictates their application order when their precedence fails to define one. With the exception of assignment operators that asssociate right to left, all operators associate left to right.

    a + b + c

has a summed with b before being summed with c.

    a = b = c

has the value of c being assigned to b before being assigned to a.

Next: , Previous: , Up: Top   [Index]