HP Pascal/iX Reference Manual (31502-90022)

5:- 1
Chapter 5 The Declaration Section
The first two parts of an HP Pascal block are the heading and the
declaration section. The heading specifies the name of the program,
module, procedure, or function. The declaration section contains
sections that define constants and user-defined types, and sections that
declare labels, variables, procedures, functions, and modules. Each of
these sections is introduced by an appropriate reserved word such as
LABEL, CONST, IMPORT, MODULE, TYPE, VAR, PROCEDURE, or FUNCTION. A block
need not include all of these sections. In HP Pascal, CONST, TYPE, VAR,
MODULE, and IMPORT declaration sections can be intermixed and must follow
label declarations and precede function or procedure declarations.
This chapter describes
constant definitions, label declarations, type
definitions,
and
variable declarations
. For information on procedure,
function, module, and import declarations, see Chapter 7 .
Constant Definition
A
constant definition
establishes an
identifier
as a synonym for a
constant value
. The identifier may then be used in place of the value.
The value of a symbolic constant may not be changed by a subsequent
constant definition in the same scope or by an assignment.
The reserved word CONST precedes one or more constant definitions. A
constant definition consists of an identifier, the equal sign, (=) and a
constant value. For more information about CONST, refer to the section
"CONST" in this chapter.
The reserved word NIL is a pointer value representing a NIL value for all
pointer types. Predeclared constants include the standard constants
maxint
and
minint
, as well as the standard Boolean constants
true
and
false
. These constants are discussed in detail in the following pages of
this chapter.
Constant expressions are a restricted class of HP Pascal expressions.
Consequently, operands in constant expressions must be
integers
,
reals
,
or
ordinal declared constants
. Operators must be +, -, *, /, DIV, or
MOD. Note that all other operators are excluded. Furthermore, only calls
to the standard functions
abs
,
binary
,
chr
,
hex
,
octal
,
odd
,
ord
,
pred
,
strlen
, and
succ
are legal.
One exception to the restrictions on constant expressions is permitted;
the sign of a
real
or
longreal
declared constant may be changed using the
negative real
unary
operator (-). The positive operator (+) is legal,
but has no effect.
In HP Pascal, constant definitions must follow label declarations and
precede function or procedure declarations. CONST, TYPE, VAR, MODULE,
and IMPORT sections may be intermixed.
Example
CONST
fingers = 10; { Unsigned integer. }
pi = 3.1415; { Unsigned real. }
message = 'Use a fork!'; { String literal. }
nothing = NIL;
delicious = true; { Standard constant. }
neg_pi = -pi; { Real unary operator. }
hands = fingers DIV 5; { Constant expression. }
numforks = pred(hands); { Constant expression with }
{ call to standard function. }