9.4 Compile-Time Expressions and Operators

The HLA CTL supports constant expressions in the CTL assignment statement. Unlike the runtime language (where you have to translate algebraic notation into a sequence of machine instructions), the HLA CTL allows a full set of arithmetic operations using familiar expression syntax. This gives the HLA CTL considerable power, especially when combined with the built-in compile-time functions the next section discusses.

Table 9-1 and Table 9-2 list operators that the HLA CTL supports in compile-time expressions.

Table 9-1. Compile-Time Operators

Operator(s)

Operand Types[a]

Description

- (unary)

numeric

Negates the specific numeric value (int, uns, real).

 

cset

Returns the complement of the specified character set.

! (unary)

integer

Inverts all the bits in the operand (bitwise not).

 

boolean

Boolean not of the operand.

*

numericL * numericR

Multiplies the two operands.

 

csetL * csetR

Computes the intersection of the two sets.

div

integerL divintegerR

Computes the integer quotient of the two integer (int/uns/dword) operands.

mod

integerL modintegerR

Computes the remainder of the division of the two integer (int/uns/dword) operands.

/

numericL / numericR

Computes the real quotient of the two numeric operands. Returns a real result even if both operands are integers.

<<

integerL << integerR

Shifts integerL operand to the left the number of bits specified by the integerR operand.

>>

integerL >> integerR

Shifts integerL operand to the right the number of bits specified by the integerR operand.

+

numericL + numericR

Adds the two numeric operands.

 

csetL + csetR

Computes the union of the two sets.

 

strL + strR

Concatenates the two strings.

-

numericL numericR

Computes the difference between numericL and numericR.

 

csetL - csetR

Computes the set difference of csetL - csetR.

= or ==

numericL = numericR

Returns true if the two operands have the same value.

 

csetL = csetR

Returns true if the two sets are equal.

 

strL = strR

Returns true if the two strings/chars are equal.

 

typeL = typeR

Returns true if the two values are equal. They must be the same type.

<> or !=

typeL <> typeR (sameas !=)

Returns false if the two (compatible) operands are not equal to one another (numeric, cset, or string).

<

numericL < numericR

Returns true if numericL is less than numericR.

 

csetL < csetR

Returns true if csetL is a proper subset of csetR.

 

strL < strR

Returns true if strL is less than strR.

 

booleanL < booleanR

Returns true if the left operand is less than the right operand (note: false < true).

 

enumL < enumR

Returns true if enumL appears in the same enumlist as enumR and enumL appears first.

<=

Same as <

Returns true if the left operand is less than or equal to the right operand. For character sets, this means that the left operand is a subset of the right operand.

>

Same as <

Returns true if the left operand is greater than the right operand. For character sets, this means that the left operand is a proper superset of the right operand.

>=

Same as <=

Returns true if the left operand is greater than or equal to the right operand. For character sets, this means that the left operand is a superset of the right operand.

&

integerL & integerR

Computes the bitwise and of the two operands.

 

booleanL & booleanR

Computes the logical and of the two operands.

|

integerL | integerR

Computes the bitwise or of the two operands.

 

booleanL | booleanR

Computes the logical or of the two operands.

^

integerL ^ integerR

Computes the bitwise xor of the two operands.

 

booleanL ^ booleanR

Computes the logical xor of the two operands. Note that this is equivalent to booleanL <> booleanR.

in

charL in csetR

Returns true if charL is a member of csetR.

[a] Type numeric is {intXX, unsXX, byte, word, dword, and realXX} values. Type cset is a character set operand. Type integer is {intXX, unsXX, byte, word, dword}. Type str is any string or character value. Type indicates an arbitrary HLA type. Other types specify an explicit HLA data type.

Table 9-2. Operator Precedence and Associativity

Associativity

Precedence (Highest to Lowest)

Operator

Right to left

6

! (unary)

  

- (unary)

Left to right

5

*

  

div

  

mod

  

/

  

>>

  

<<

Left to right

4

+

  

-

Left to right

3

= or ==

  

<> or !=

  

<

  

<=

  

>

  

>=

Left to right

2

&

  

|

  

^

Nonassociative

1

in

Of course, you can always override the default precedence and associativity of an operator by using parentheses in an expression.