Values
Each value processed by heitml has one of the 6 above-described data types
associated with it. Integer, Boolean, real, and string are different types.
There is a difference between 6 as an integer value, "6" as a string, and 6.0
as a real value. Also, true as Boolean value and "true" as a string are
different. The special value null is the only value which has the
type unknown.
Variables
Each heitml variable has an identifier, which must be declared when a value
is first assigned to it. heitml is a Dynamically Typed Language, which
means that variable types are assigned according to the type of data
associated with it. Later, the variable type can change simply by assigning
it a new type of data.
Variables are local to the current heitml-page or to the current invocation of a procedure.
heitml also provides the concept of Global Variables which
means that all procedures can access these variables.
Assignments
Assignments occur when explicitly written down with the = operator, when
using the assign, dbquery, for or forin tag, and
implicitly during parameter passing.
Assignments of all types except object have the usual value semantics, the
whole value is copied. For objects, pointer semantics applies. This means an
object is allocated on the heap and an object variable always contains a
reference. Assignment assigns this reference.
Operations
heitml knows the operators + (add), - (subtract), * (multiply), / (divide),
% (modulo) which work as usual on integer and real operands.
The plus symbol + can also be used to concatenate strings.
Using the minus symbol - as an unary operator, numeric values are
negated.
Operator Precedence
Operator operands may contain expressions called sub-expressions,
so expressions have a tree structure with the root at the top.
When an expression evaluated, there is a certain order to how it is done.
Operands are always evaluated first, so the tree is evaluated from the
leaves to the root.
Unfortunately, the tree structure of an expression is not unique on user input.
For example, the expression
2*2+2
may be evaluated to 8 if
2
and
2+2
are considered as the operands of the
*
operator or it may be evaluated to 6 if
2*2
and
2
are considered as the operands of the
+
operator.
To make expressions unique, operators have precedence over other
operators. The operator precedence is defined below.
In our example, the
*
operator
has precedence over the
+
operator and so the expression is evaluated to 6.
The user can overrule the default operator precedence, by parenthesizing sub-expressions.
For example, to evaluate the previous expression to 8, the user would have to
write the expression as
2*(2+2).
The following list shows the operators with ascending precedence:
, = || &&
== != < <= &ge > &le <
+ - * / %
unary - ! . [ ] ( ).
Type checking
The type of an expression type is determined by its constituents.
If an expression is a constant or variable, the type of the expression is the
type of the constant or variable.
If an expression consists of an operator with its operands
the type of the expression is the type of the operators result which itself may
depend on the type of the operands.
For example, expressions consisting of comparison operators
(also called conditions)
are independent of the type of the operands and always will result
in value of type Boolean.
In contrast, expressions with a
+
operator have a type dependent on the type of the operands.
The type of the expression
2+2
is integer
and the type of
"a"+"b"
is a string.
Except for the operators =, ,, ==, and !=, the type of the left operand and the right operand must be the same. If necessary, the following coercions are done on the operands:
| Coercion on | left operand | | Coercion on | right operand | |
| Real ( | Integer ) | | | Real |
| Real | | Real ( | Integer ) |
| String | | String ( | Integer ) |
| String ( | Integer ) | | | String |
| String | | String ( | Real ) |
| String ( | Real ) | | | String |
The following table summarizes which operators expect which operand types.
A '*' entry means that the operator does not care about operand types.
All other combinations result in the error message "Type error in expression".
| Operator | type of left operand | type of right operand | Result type |
| , = | * | type of right operand |
| == != | * | Boolean |
| || && | Boolean | Boolean |
| < <= &ge > &le < | Real, Integer, String, Boolean | Boolean |
| + | Real, Integer, String | Real, Integer, String, respectively |
| - * / % | Real, Integer | Real, Integer, respectively |
| unary - | Real, Integer | not applicable | Real, Integer, respectively |
| ! | Boolean | not applicable | Boolean |
| . | Object | * | type of object field or result of method call |
| [ ] | Object | String, Integer | type of object field or result of method call |
| String | Integer | String |
| ( ) | * | not applicable | * |