VMS Help
PASCAL, Expressions, Operators
*Conan The Librarian (sorry for the slow response - running on an old VAX)
|
|
Pascal provides several classes of operators. You can form
complex expressions by using operators to combine constants,
constant identifiers, variables, and function designators.
An arithmetic operator usually provides a formula for
calculating a value. To perform arithmetic operations, numeric
operands are combined with one or more of the arithmetic
operators.
Arithmetic Operators:
operator | example | result
--------------------------------------------
+ A + B Sum of A and B
- A - B B subtracted from A
* A * B Product of A and B
** A ** B A raised to the power of B
/ A / B A divided by B
DIV A DIV B Result of A divided by B,
truncated toward zero
REM A REM B Remainder of A divided by B
MOD A MOD B Modulus of A with respect to B
A relational operator tests the relationship between two
ordinal, real, DOUBLE, or QUADRUPLE expressions and returns a
Boolean value. If the relationship holds, the result is TRUE;
otherwise the result is FALSE. You can also apply some of the
relational operators to string operands and to set operators.
Relational Operators:
operator | example | result
--------------------------------------------
<> A <> B TRUE if A is not equal to B
< A < B TRUE if A is less than B
<= A <= B TRUE if A is less than or equal to B
> A > B TRUE if A is greater than B
>= A >= B TRUE if A is greater than or equal to B
A logical operator evaluates one or more Boolean expressions and
returns a Boolean value.
Logical Operators:
operator | example | result
-------------------------------------------------
AND A AND B TRUE if both A and B are TRUE
OR A OR B TRUE if either A or B is TRUE,
or if both are TRUE
NOT NOT A TRUE if A is FALSE, and
FALSE if A is TRUE
AND_THEN A AND_THEN B TRUE if both A and B are TRUE
(forces left-to-right evaluation
order with short-circuiting)
OR_ELSE A OR_ELSE B TRUE if either A or B is TRUE,
or if both are TRUE
(forces left-to-right evaluation
order with short-circuiting)
A string operator concatenates or compares character-string
expressions. The result is either a string or a Boolean value.
String Operators:
operator | example | result
--------------------------------------------
+ A + B String that is the concatenation of strings
<> A <> B TRUE if strings A and B have unequal ASCII
values
< A < B TRUE if the ASCII value of string A is less
than that of string B
<= A <= B TRUE if the ASCII value of string A is less
than or equal to that of string B
> A > B TRUE if the ASCII value of string A is greater
than that of string B
>= A >= B TRUE if the ASCII value of string A is greater
than or equal to that of string B
A set operator forms the union, intersection, difference, or
exclusive-OR of two sets, compares two sets, or tests an ordinal
value for inclusion in a set. Its result is either a set or a
Boolean value.
Set Operators:
operator | example | result
--------------------------------------------
+ A + B Set that is the union of sets A and B
* A * B Set that is the intersection of sets A
and B
- A - B Set of those elements in set A that are
not also in set B
<> A <> B TRUE if set A is not equal to set B
<= A <= B TRUE if set A is a subset of set B
>= A >= B TRUE if set B is a subset of set A
IN C IN B TRUE if C is an element of set B
The type cast operator changes the context in which a variable
or an expression of a certain data type can be used. The actual
representation of the object being cast is not altered by the
type cast operator. Compaq Pascal overrides the type only for
the duration of one operation. It has one of the following
forms:
variable-identifier :: type-identifier
(expression) :: type-identifier
The type cast operator (::) separates the name of the variable
or an expression in parentheses from its target type, the type
to which it is being cast.
Example:
TYPE
F_Float = PACKED RECORD
Frac1 : 0..127;
Expo : 0..255;
Sign : Boolean;
Frac2 : 0..65535;
END;
VAR
A : REAL;
{In the executable section:}
A :: F_Float.Expo := A :: F_Float.Expo + 1;
The record type 'F_Float' illustrates the layout of an
F_floating real number. The real variable 'A' is cast as a
record of this type, allowing access to the fields containing
the mantissa, exponent, sign, and fraction of 'A'. Adding 1 to
the field containing the exponent would give the same result as
multiplying 'A' by 2.0.
[legal]
[privacy]
[GNU]
[policy]
[netiquette]
[sponsors]
[FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.