Tokens
Tokens are the smallest meaningful units of text in an Object Pascal program. They are categorized as special symbols, identifiers, labels, numbers, and string constants.
An Object Pascal program is made up of tokens and separators. A separator is either a blank or a comment. Two adjacent tokens must be separated by one or more separators if each token is a reserved word, an identifier, a label, or a number.
Separators can’t be part of tokens except in string constants.
Special symbols
Object Pascal uses the following subsets of the ASCII character set:
-
Letters—the English alphabet, A through Z and a through
z
-
Digits—the Arabic numerals 0 through 9
-
Hex digits—the Arabic numerals 0 through 9, the letters A through F, and the letters a through f
-
Blanks—the space character (ASCII 32) and all ASCII control characters (ASCII 0 through 31), including the end-of-line or return character (ASCII 13)
These are the syntax diagrams for letter, digit, and hex digit:
letter
digit
hex digit
Special symbols and reserved words are characters that have one or more fixed meanings. The following single characters are special symbols:
####### + - * / = < > [ ] . , ( ) : ; ^ @ { } $ #
These character pairs are also special symbols:
####### <= >= := .. (* *) (. .)
A left bracket ([) is equivalent to the character pair of left parenthesis and a period— (., and a right bracket (]) is equivalent to the character pair of a period and a right parenthesis—.). Likewise, a left brace ({) is equivalent to the character pair of left parenthesis and an asterisk—(*, and a right brace (}) is equivalent to the character pair of an asterisk and a right parenthesis—*).
Reserved words and standard directives
Reserved words can’t be redefined.
Reserved words appear in lowercase boldface throughout this manual. Object Pascal is not case sensitive, however, so you can use either uppercase or lowercase letters in your programs.
Following are Obejct Pascal’s reserved words:
Table 1-1 Object Pascal reserved words
and |
exports |
library |
set |
---|---|---|---|
array |
file |
mod |
shl |
as |
finally |
nil |
shr |
asm |
for |
not |
string |
begin |
function |
object |
then |
case |
goto |
of |
to |
class |
if |
on |
try |
const |
implementation |
or |
type |
constructor |
in |
packed |
unit |
destructor |
inherited |
procedure |
until |
div |
initialization |
program |
uses |
do |
inline |
property |
var |
downto |
interface |
raise |
while |
else |
is |
record |
with |
end |
label |
repeat |
xor |
except |
The following are Object Pascal’s standard directives. Directives are used only in contexts where user-defined identifiers can’t occur. Unlike reserved words, you can redefine standard directives, but we advise that you don’t.
Table 1-2 Object Pascal directives
absolute |
export |
name |
published |
---|---|---|---|
abstract |
external |
near |
read |
assembler |
far |
nodefault |
resident |
at |
forward |
override |
stored |
cdecl |
index |
private |
virtual |
default |
interrupt |
protected |
write |
dynamic |
message |
public |
private, protected, public, and published act as reserved words within object type declarations, but are otherwise treated as directives.
Identifiers
Identifiers denote constants, types, variables, procedures, functions, units, programs, and fields in records.
An identifier can be of any length, but only the first 63 characters are significant. An identifier must begin with a letter or an underscore character (_) and can’t contain spaces. Letters, digits, and underscore characters (ASCII $5F) are allowed after the first character. Like reserved words, identifiers are not case sensitive.
When several instances of the same identifier exist, you may need to qualify the identifier by another identifier to select a specific instance. For example, to qualify the identifier Ident by the unit identifier UnitName, write UnitName.Ident. The combined identifier is called a qualified identifier. Units are described on page 206 of the Delphi User’s Guide and Chapter 11 of this manual.
identifier
underscore
qualified identifier
.
Here are some examples of identifiers and qualified identifiers:
Writeln Exit Real2String
System.MemAvail SysUtils.StrLen WinCrt.ReadText
In this manual, standard and user-defined identifiers are italicized when they are referred to in text.
Numbers
Ordinary decimal notation is used for numbers that are constants of integer and real types. A hexadecimal integer constant uses a dollar sign ($) as a prefix. Engineering notation (E or e, followed by an exponent) is read as “times ten to the power of” in real types. For example, 7E-2 means 7 x 10-2; 12.25e+6 or 12.25e6 both mean 12.25 x 10+6. Syntax diagrams for writing numbers follow:
hex digit sequence
digit sequence
unsigned integer
sign
unsigned real
scale factor
unsigned number
signed number
Labels
Numbers with decimals or exponents denote real-type constants. Other decimal numbers denote integer-type constants; they must be within the range -2,147,483,648 to 2,147,483,647.
Hexadecimal numbers denote integer-type constants; they must be within the range
$00000000 to $FFFFFFFF. The resulting value’s sign is implied by the hexadecimal notation.
A label is a digit sequence in the range 0 to 9999. Leading zeros are not significant. Labels are used with goto statements.
label
As an extension to Standard Pascal, Object Pascal allows identifiers to function as labels.
Character strings
A character string is a sequence of zero or more characters from the extended ASCII character set, written on one line in the program and enclosed by apostrophes.
A character string with nothing between the apostrophes is a null string. Two sequential apostrophes in a character string denote a single character, an apostrophe. For example,
'BORLAND' { BORLAND }
'You''ll see' { You'll see }
'''' { ' }
'' { null string }
' ' { a space }
Object Pascal lets you embed control characters in character strings. The # character followed by an unsigned integer constant in the range 0 to 255 denotes a character of the corresponding ASCII value. There must be no separators between the # character and the integer constant. Likewise, if several are part of a character string, there must be no separators between them. For example,
#13#10
'Line 1'#13'Line2' #7#7'Wake up!'#7#7
character string
quoted string
string character
control string
A character string’s length is the actual number of characters in the string. A character string of any length is compatible with any string type, and with the PChar type when the extended syntax is enabled {$X+}. Also, a character string of length one is compatible with any Char type, and a character string of length N, where N is greater than or equal to one, is compatible with packed arrays of N characters.
Comments
The following constructs are comments and are ignored by the compiler:
{ Any text not containing right brace }
(* Any text not containing star/right parenthesis *)
A comment that contains a dollar sign ($) immediately after the opening { or (* is a
compiler directive. A mnemonic of the compiler command follows the $ character.
Program lines
Object Pascal program lines have a maximum length of 126 characters.
C h a p t e r