Identifiers are names that allow you to reference stored values, such as
variables and constants. Also, every program and unit must be named by an
identifier.
Rules for identifiers:
- Must begin with a letter from the English alphabet.
- Can be followed by alphanumeric characters (alphabetic characters
and numerals) and possibly the underscore (_).
- May not contain certain special characters, many of which have
special meanings in Pascal.
~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / |
Different implementations of Pascal differ in their rules on special
characters. Note that the underscore character (_) is usually allowed.
Several identifiers are reserved in Pascal as syntactical
elements. You are not allowed to use these for your identifiers. These
include but are not limited to:
and array
begin case
const div
do downto
else end
file for
forward
function goto
if in
label mod
nil not
of or
packed
procedure program
record repeat
set then
to type
until var
while with
|
Modern Pascal compilers ship with much functionality in the API
(Application Programming Interfaces). For example, there may be one unit for
handling graphics (e.g. drawing lines) and another for mathematics. Unlike
newer languages such as C# and Java, Pascal does not provide a
classification system for identifiers in the form of namespaces. So each
unit that you use may define some identifiers (say DrawLine)
which you can no longer use. Pascal includes a system unit which is
automatically used by all programs. This provides baseline functionality
such as rounding to integer and calculating logarithms. The system unit
varies among compilers, so check your documentation. Here is the
system
unit documentation for Free Pascal Compiler.
Pascal is not case sensitive! (It was created in the days when
all-uppercase computers were common.) MyProgram,
MYPROGRAM, and mYpRoGrAm are equivalent. But for
readability purposes, it is a good idea to use meaningful capitalization.
Most programmers will be on the safe side by never using two
capitalizations of the same identifiers for different purposes, regardless
of whether or not the language they're using is case-sensitive. This reduces
confusion and increases productivity.
Identifiers can be any length, but some Pascal compilers will only look
at the first several characters. One usually does not push the rules with
extremely long identifiers or loads of special characters, since it makes
the program harder to type for the programmer. Also, since most programmers
work with many different languages, each with different rules about special
characters and case-sensitivity, it is usually best to stick with
alphanumeric characters and the underscore character.