t3x.org / t3x / t3x-manual / 271.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
2.7 Statements
TOC | Index | Back Next:
2.7.2 Procedure Calls

2.7.1 Assignments

An assignment is used to transfer the value of an expression to a specific storage location. For example, the statement

A := B;

copies the value of B to A. After the assignment, both variables will have the same value. The previous value of B is thereby lost.

The righthand side of an assigment may be any valid expression as described in the previous section. The lefthand side is restricted to a subset of expressions which is frequently referred to as lvalues (lefthand side values). In T3X, each lvalue may be one of the following:

(*) Vector members and structure members are basically the same.

Assignments to vector members are in no way limited; addressing elements of multiply nested vectors is perfectly legal. The evaluation of variables on lefthand and righthand sides of assignments was explained in detail in the section about factors. In short, on righthand sides variables evaluate to their values and on lefthand sides they evaluate to their addresses. The assignment operator := first evaluates the expression on its left side and remembers the resulting address. Then it evaluates the expression to its right and stores the result at the memorized address.

A generalization of the evaluation of lefthand sides is the following: Each but the last reference on a lefthand side of an assignment evaluates to its value. Only the last reference evaluates to its address. Here are some examples:

A := B;

The symbol A references a specific storage location. Since it is the only reference in the lvalue, it evaluates to its address. In the statement

A[i] := B;

A is not the last reference and hence it yields its value (which is its address in case A is a vector). The operation [i] references the i'th member of A. Since it is the last reference on the lefthand side, it evaluates to the address of A[i] instead of its value. Consequently, the following assignment operator stores B at the address of the i'th member of A. The same is valid for the access of vector elements at any nesting level. The statement

A[i1][i2][i3][i4] := B;

for example, stores B in the i4'th member of A[i1][i2][i3].

Accessing byte vectors works in the same way:

A::i := B;

stores the least significant eight bits of B in the i'th byte of A.

Since :: associates to the right, the last evaluated reference is the leftmost one in chains of byte operators like

A::B::i := C;

Because B::i will be evaluated first in this example, it will yield its value. Then, the address of A::(B::i) is computed. Since no more references are following after A::, the (least significant eight bits of the) value of C will be stored in the (B::i)'th byte of A.

Note: Although the assignment symbol := looks like an operator (and is frequently even referred to as such), it may not be used inside of expressions, but only to combine expressions, thereby turning them into a statement.

Previous:
2.7 Statements
TOC | Index | Back Next:
2.7.2 Procedure Calls