Subsections

1 Pascal Tokens

In this chapter we describe all the pascal reserved words, as well as the various ways to denote strings, numbers, identifiers etc.

1 Symbols

Free Pascal allows all characters, digits and some special ASCII symbols in a Pascal source file.

Recognised symbols

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{letter} \( \lit*{A ... Z} \\ \lit*{a ... z} \)\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{digit} \lit*{0 ... 9}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{hex\ digit}
\( \lit*{0 ... 9} \\ \lit*{A ... F} \\ \lit*{a ...f} \)\end{syntdiag}
The following characters have a special meaning:
 + - * / = < > [ ] . , ( ) : ^ @ { } $ #
and the following character pairs too:
<= >= := += -= *= /= (* *) (. .) //
When used in a range specifier, the character pair (. is equivalent to the left square bracket [. Likewise, the character pair .) is equivalent to the right square bracket ]. When used for comment delimiters, the character pair (* is equivalent to the left brace { and the character pair *) is equivalent to the right brace }. These character pairs retain their normal meaning in string expressions.

2 Comments

Free Pascal supports the use of nested comments. The following constructs are valid comments:
(* This is an old style comment *)
{  This is a Turbo Pascal comment }
// This is a Delphi comment. All is ignored till the end of the line.
The following are valid ways of nesting comments:
{ Comment 1 (* comment 2 *) }
(* Comment 1 { comment 2 } *)
{ comment 1 // Comment 2 }
(* comment 1 // Comment 2 *)
// comment 1 (* comment 2 *)
// comment 1 { comment 2 }
The last two comments must be on one line. The following two will give errors:
 // Valid comment { No longer valid comment !!
    }
and
 // Valid comment (* No longer valid comment !!
    *)
The compiler will react with a 'invalid character' error when it encounters such constructs, regardless of the -So switch.

3 Reserved words

Reserved words are part of the Pascal language, and cannot be redefined. They will be denoted as this throughout the syntax diagrams. Reserved words can be typed regardless of case, i.e. Pascal is case insensitive. We make a distinction between Turbo Pascal and Delphi reserved words, since with the -So switch, only the Turbo Pascal reserved words are recognised, and the Delphi ones can be redefined. By default, Free Pascal recognises the Delphi reserved words.

1 Turbo Pascal reserved words

The following keywords exist in Turbo Pascal mode
absolute
and
array
asm
begin
break
case
const
constructor
continue
destructor
div
do
downto
else
end
file
for
function
goto
if
implementation
in
inherited
inline
interface
label
mod
nil
not
object
of
on
operator
or
packed
procedure
program
record
repeat
self
set
shl
shr
string
then
to
type
unit
until
uses
var
while
with
xor

2 Delphi reserved words

The Delphi (II) reserved words are the same as the pascal ones, plus the following ones:
as
class
except
exports
finalization
finally
initialization
is
library
on
property
raise
try

3 Free Pascal reserved words

On top of the Turbo Pascal and Delphi reserved words, Free Pascal also considers the following as reserved words:
dispose
exit
false
new
true

4 Modifiers

The following is a list of all modifiers. Contrary to Delphi, Free Pascal doesn't allow the programmer to redefine these modifiers.
absolute
abstract
alias
assembler
cdecl
default
export
external
far
forward
index
name
near
override
pascal
popstack
private
protected
public
published
read
register
saveregisters
stdcall
virtual
write

Remark: Predefined types such as Byte, Boolean and constants such as maxint are not reserved words. They are identifiers, declared in the system unit. This means that these types can be redefined in other units. The programmer is, however, not encouraged to do this, as it will cause a lot of confusion.

4 Identifiers

Identifiers denote constants, types, variables, procedures and functions, units, and programs. All names of things that are defined are identifiers. An identifier consists of 255 significant characters (letters, digits and the underscore character), from which the first must be an alphanumeric character, or an underscore (_) The following diagram gives the basic syntax for identifiers.

Identifiers

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{identifier} \...
...b]\\
\(
\synt{letter} \\
\synt{digit} \\
\lit*{\_}
\)\end{rep}\end{syntdiag}

5 Numbers

Numbers are denoted in decimal notation. Real (or decimal) numbers are written using engeneering notation (e.g. 0.314E1). Free Pascal supports hexadecimal format the same way as Turbo Pascal does. To specify a constant value in hexadecimal format, prepend it with a dollar sign ($). Thus, the hexadecimal $FF equals 255 decimal. In addition to the support for hexadecimal notation, Free Pascal also supports binary notation. A binary number can be specified by preceding it with a percent sign (%). Thus, 255 can be specified in binary notation as %11111111. The following diagrams show the syntax for numbers.

Numbers

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{hex\ digit\ sequence}
\begin{rep}[b]
\synt{hex\ digit} \\
\end{rep} \end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{bin\ digit\ s...
...
\begin{stack}
\lit*{1} \\ \lit*{0}
\end{stack} \\
\end{rep} \end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{digit\ sequence}
\begin{rep}[b]
\synt{digit} \\
\end{rep} \end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{unsigned\ int...
...uence} \\
\lit*{
\%
} \synt{bin\ digit\ sequence}
\end{stack}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy sign \begin{stack}\lit* + \\ \lit* - \end{stack}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{unsigned\ rea...
...ymath}\begin{displaymath}
\synt{scale\ factor}
\end{displaymath}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{scale\ factor...
...ack}\begin{stack}\\ \synt{sign} \end{stack} \synt{digit\ sequence}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{unsigned\ num...
...ack}\synt{unsigned\ real} \\
\synt{unsigned\ integer} \end{stack}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{signed\ number} \begin{stack}\\ \synt{sign} \end{stack}\synt{unsigned\ number}\end{syntdiag}

6 Labels

Labels can be digit sequences or identifiers.

Label

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{label} \( \synt{digit\ sequence} \\ \synt{identifier} \)\end{syntdiag}

Remark: Note that the -Sg switch must be specified before labels can be used. By default, Free Pascal doesn't support label and goto statements.

7 Character strings

A character string (or string for short) is a sequence of zero or more characters from the ASCII character set, enclosed by single quotes, and on 1 line of the program source. A character set with nothing between the quotes ('') is an empty string.

Character strings

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{character\ st...
...}[b]\( \synt{quoted\ string} \\ \synt{control\ string} \)\end{rep}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{quoted\ strin...
...it*{'}
\begin{rep}[b]\synt{string\ character} \\ \end{rep}\lit*{'}\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{string\ character}
\(
\tok{ Any character except ' or CR} \\
\lit*{''}
\)\end{syntdiag}

\begin{syntdiag}\setlength{\sdmidskip}{.5em}\sffamily\sloppy \synt{control\ stri...
...gin{rep}[b]
\lit*{\char93 } \synt{unsigned\ integer} \\
\end{rep}\end{syntdiag}


Free Pascal Compiler
2001-09-22