10.5 Compile Time Expressions and Operators


10.5 Compile Time Expressions and Operators

As the previous section states, the HLA CTL supports constant expressions in the CTL assignment statement. Unlike the run-time 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.

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

Table 10-1: Compile Time Operators

Operator(s)

Operand Types[1]

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 div integerR

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

mod

integerL mod integerR

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 (same as =)

Returns false if the two (compatible) operands are not equal to one another.

<

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 left operand is less than right operand (note: false < true).

enumL < enumR

Returns true if enumL appears in the same enum list 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 logical AND of the two operands.

booleanL & booleanR

Computes the bitwise 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.

[1]Numeric is {intXX, unsXX, byte, word, dword, and realXX} values. 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 10-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.




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net