The Hyper Programming Language

Unary Operator Expressions

General

Unary operator expressions are expressions that consist of an operator prefix followed by an expression operand. An important thing to note is that the operand of a unary operator expression is expected to be a non-pointer type. If the operand has a pointer type, then it is automatically dereferenced.

Unary operators

Hyper has the following unary operators:

Operator Meaning
- Unary minus
+ Unary plus
! Not
++ Successor
-- Predecessor

The first three operators in the table are straightforward for anyone who knows Java or C++. The last two, however, need some explanation.

The successor expression may look like a pre-increment, but it is not!. In fact, the successor expression does what its name says: it just gives the value right after the value of its operand. For example, ++5 gives 6 as a result. Likewise, the expression --5 returns the value 4. Those two expressions don't modify their operand, so they do not require their operand to be an L-value. If you need increment or decrement that changes its operand, then take a look at the increment/decrement statements.

Example

procedure p()
  var a & b & c & d : int
  a = 12
  b = 9
  c = ++a   # c becomes 12 + 1 = 13
  d = ++b * --b  # d becomes (9 + 1) * (9 - 1) = 10 * 8 = 80
  c = - -- -- + a   # c becomes -((+12 - 1) - 1) = -10
  var s : bool = !false  # s is true
end

See also


Valid HTML 4.01 Strict Valid CSS!