Identifiers [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation
HP Pascal/iX Reference Manual
Identifiers
An HP Pascal identifier consists of a letter preceding an optional
character sequence of letters, digits, or the underscore character (_) up
to a source line in length with all characters significant without
respect to case.
Identifiers are used to denote declared constants, types, variables,
procedures, functions, modules, and programs.
A letter may be any of the letters in the subranges A through Z or a
through z. The compiler makes no distinction between upper and lower
case in identifiers. A digit may be any of the digits 0 through 9. The
underscore (_) is an HP Standard Pascal extension of ANSI/IEEE770X3.97 -
1983 Standard Pascal.
In general, an identifier must be defined before using it. Four
exceptions are:
* Identifiers that define pointer types and are themselves defined
later in the same declaration part.
* Identifiers that appear as program parameters and are declared
subsequently as variables.
* Predefined identifiers such as integer and char.
* Forward procedures or functions.
An identifier does not need to be defined when it is a program, module,
procedure, or function name, or one of the identifiers defining an
enumerated type. Its initial appearance in a function, procedure,
module, or program header is the "defining occurrence."
Finally, HP Pascal has a number of standard identifiers that may be
redeclared. These standard identifiers include names of standard
procedures and functions, standard file variables, standard types,
standard constants, and procedure or function directives.
Reserved words are language defined symbols whose meaning can never
change. Therefore, an identifier cannot be declared that has the same
spelling as a reserved word.
For a list of reserved words recognized by HP Pascal, see Table 2-2 .
Syntax
Identifier:
Example
GOOD_TIME_9 { These identifiers }
good_time_9 { are }
gOOd_TIme_9 { equivalent. }
x2_GO
a_long_identifier
Boolean { Standard identifier.}
Scope
The scope of an identifier is its domain of accessibility or the region
of a program in which it may be used. In general, a user-defined
identifier can appear anywhere in a block after its definition.
Furthermore, the identifier can appear in a block nested within the block
in which it is defined.
If an identifier is redefined in a nested block, however, this new
definition takes precedence in the entire block. The object defined at
the outer level is no longer accessible from the inner level. Once
defined at a particular level, an identifier may not be redefined at the
same level, except for field names.
Labels are not identifiers, and their scope is restricted. They cannot
mark statements in blocks nested within the block where they are
declared.
Identifiers defined at the main program level are global. Identifiers
defined in a function or procedure block are local to the function or
procedure. The definition of an identifier must precede its use, with
the exception of pointer type identifiers, program parameters, predefined
identifiers, and forward declared procedures or functions.
For a module, identifiers declared in the EXPORT section are valid for
the entire module. Identifiers declared after the IMPLEMENT keyword are
valid only within the IMPLEMENT part of the module.
When a module is imported, the identifiers in the EXPORT section of the
imported module are placed in the global scope of the program. Because
of this, the identifiers in the EXPORT section must be unique not only
within the module, but also within the global scope of a program.
Example
PROGRAM show_scope (output);
CONST
asterisk = '*';
VAR
x: char; {global variable}
PROCEDURE writeit;
CONST
x = 'LOCAL AND GLOBAL IDENTIFIERS DO NOT CONFLICT';
BEGIN
write (x)
END; {writeit}
BEGIN { show_scope }
x:= asterisk;
write (x);
writeit;
write (x);
writeln;
END. { show_scope }
RESULTS:
*LOCAL AND GLOBAL IDENTIFIERS DO NOT CONFLICT*
MPE/iX 5.0 Documentation