Expressions can occur as parameters for heitml and user-defined tags. They are evaluated before execution of a specific tag.
heitml knows the following data types:
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.
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 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.
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.
Binary Boolean expressions use the operators ==, !=, <, <=, <, >, &le, &ge, ||, &&. Note that there is no > operator for syntactical reasons. < stands for less than, &le for less or equal, > for greater than, and &ge for greater or equal.
Unary Boolean expressions consist of the not operator ! followed by a Boolean expression.
The assignment operator = assigns the right operand to the left operand and returns the result of the right operand.
Therefore, the left operand must denote a variable or a field of an object.
The operator , evaluates both operands and returns the result of the second operand.
Note that expression with the operators = and , must be parenthesized within the expression of the ? tag, the condition of the while and if statement, within the operator [ ], in parameters of a function call and default values of function parameters.
The operator [ ] is used to index an object or a string. In the case of an object, the operator [ ] is used to access an object field or to call a method of an object.
If a string s is indexed through s[i], the index i must be of type integer denoting the i-th character of s, where counting starts with 0. For indexing an object with the [ ] operator, refer to the Objects page.
The operator . is used to access an object field or to call a method of an object.
Finally, an operation maybe a function call.
For more information about function calls, refer to the Methods page.
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 - ! . [ ] ( ).
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:
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".
© 1996-2017 H.E.I. All Rights Reserved.