Language Syntax

Expressions


An
expression may be a numeric constant, a string constant, an array reference, a call to a typed (function) procedure, or any combination of the above elements, in combination with one or more unary or binary operators. Every expression is characterized by a data type and a value. The data type is fixed at compile time, but the value may be either fixed at compile time, or calculated at run time. Parentheses may be used to force the compiler to evaluate the parts of an expression in a certain order. In the absence of parenthesis, the precedence of an operator determines the order of evaluation of an expression. The highest precedence operators are evaluated first. The precedence of the SPP operators is defined by the order in which the operators appear in the table under heading "Data Types" on page 8. Procedure call has the highest precedence. The argument list in a procedure or array reference consists of a list of general expressions separated by commas. If an expression contains calls to two or more procedures, the order in which the procedures are evaluated is undefined.

Operators

SPP supports the usual arithmetic operators which take operands of any numeric data type. In addition there are the usual comparison operators which take operands of any data type with the data type of the result always boolean. Finally, there are boolean operators taking boolean operands and also resulting in a boolean.

Table 1.8: Arithmetic and Boolean Operators.

Minus (-) may be a binary operator (have two arguments) or unary operator (have one argument) operator. As a binary operator it represents subtraction and as a unary operator it represents negation. The boolean not (!) is always a unary operator.

Mixed Mode Expressions

Binary operators combine two expressions into a single expression. If the two input expressions are of different data types, the expression is said to be a mixed mode expression. The data type of a mixed mode expression is defined by the order in which the types of the two input expressions appear in the table under "Data Types" on page 8. The data types are listed in the table in order of increasing precedence. Thus, the data type which appears furthest down in this table will be the data type of the combined expression. For example, an int plus a real produces a real. Mixed mode expressions involving bool are illegal. While char expressions are permitted, there are no string operators or expressions since there is no fundamental string data type.

Type Coercion

Type coercion refers to the conversion of an object from one data type to another. Such conversions may involve loss of information, and hence are not always reversible. Type coercion occurs automatically in mixed mode expressions, and in assignment statements. Type coercion is not permitted between booleans and the other data types.

Table 1.9: Data Type Precedence.

The data type of an expression may be coerced by a call to an intrinsic function. The names of these intrinsic functions are the same as the names of the data types. Thus, int(x), where x is of type real, coerces x to type int, while double(x) produces a double precision result.

The Assignment Statement

The assignment statement assigns the value of the general expression on the right side to the variable or array element given on the left side. Automatic type coercion will occur during the assignment if necessary (and legal). Multiple assignments may not be made in a single assignment statement. That is, an assignment statement may have only one equal sign. However, a line may contain more than one statement, separated by semicolons (;).

Operators
Table 1.8: - Arithmetic and Boolean Operators.
Mixed Mode Expressions
Type Coercion
Table 1.9: - Data Type Precedence.
The Assignment Statement

Generated with CERN WebMaker