The Hyper Programming Language

Assignment Statement

General

Unlike in C++ and Java, assignments can not be used as expressions in Hyper. Because of this, the assignment operator '=' can be also used as the equality operator. And therefore, you cannot use an accidental assignment in an 'if' statement. Apart from this main difference, there is probably nothing you don't already know about assignment statements.

Syntax

The general syntax for assignments is:

L-value operator R-value

An L-value is similar to L-values in other languages. The syntax of an L-value is in general like a postfix operator expression. This means that it consists of an identifier followed by any number of array selection operators, function call operators, and member selection operators. But an L-value must also be assignable, of course.

As an R-value you can use almost any expression. The only constraint is that the L-value and R-value must be assignment compatible for the operator that is used.

Here is a list of all the assignment operators that can be used:

Operator Meaning
= Assign
=$ Pointer assign
+= Add & assign
-= Subtract & assign
*= Multiply & assign
/= Divide & assign
%= Modulo & assign
&= And & assign
|= Or & assign

Examples

procedure p()
  var x & y & z : int
  var p : * int
  x = y + z  # assign the value y + z to x
  p =$ x     # assign the address of x to the pointer p
  x += p     # add x to the value pointed to by p and assign the result to x
  p *= z     # multiply the value pointed to by p with z and assign the result to the place p points to
end

See also


Valid HTML 4.01 Strict Valid CSS!