Chapter 6. Expressions

Table of Contents

Atomic Values
Operator Precedence
The new Operator
Increment and Decrement Operators
Type Casts
Arithmetic Operators
Comparison Operators
Logical Operators
Assignment Operators

An expression is anything that can be evaluated to a value. Examples of expressions in RSP include variable references (which evaluate to the value of the variable), function calls (provided the function returns a value), addition (e.g. 3 + 4), and many others.

Expressions are built out of atomic values and operators. The type of an expression is the data type that it evaluates to.

Atomic Values

Atomic values are the building blocks of expressions. An atomic value on its own is a valid expression, or you can combine atomic values together using operators. There are several types of atomic value in RSP:

  • Variable references.

  • Literals.

  • Function calls.

  • Calls to void functions (functions that do not return a value). This is a special case - a void function call has no return type and so cannot be combined with any other atomic value by means of operators, but for the purposes of the language specification it is an expression and can be used anywhere where an expression is allowed (except where there are constraints on the type of the expression).


An lvalue is anything that may appear on the left hand side of an assignment, i.e. a variable name. Note that variables declared as constants are not lvalues because they cannot be assigned to after their declaration.