Introduction to Pascal
last modified November 18, 2026 Free Pascal 3.2.2
Pascal is a compiled, statically typed programming language designed by Niklaus Wirth and published in 1970. It was created as a small, readable language for teaching structured programming, and it grew into one of the most influential languages of the personal-computer era. This article introduces the language and its dialects, installs Free Pascal, and compiles and runs the first programs.
What is Pascal
Niklaus Wirth developed Pascal at ETH Zurich between 1968 and 1970. It followed his earlier language Algol W and was derived from Algol 60, from which it took the block structure, the nested procedures, and the idea that every variable has a fixed type. Wirth wanted a language that a compiler could translate efficiently and that a student could learn completely. The result is small enough to describe in a short report, yet expressive enough for real programs.
The name honours Blaise Pascal, the seventeenth-century mathematician and philosopher. The first implementation ran on the CDC 6000 series, and the language spread quickly through universities. Its emphasis on structured control flow, explicit declarations, and readable syntax made it the standard teaching language of the 1970s and 1980s. The same qualities made it a practical systems language: the first Macintosh operating system was written in Pascal, and many early applications were too.
Pascal is an imperative language. A program is a sequence of statements, and the statements change the values stored in variables. The language provides integers, reals, Booleans, characters, strings, arrays, records, sets, files, and pointers. Later dialects added classes, interfaces, exceptions, generics, and units. Pascal is also strongly typed: every expression has a type, and the compiler rejects most combinations that do not make sense, which catches many mistakes before the program runs.
Pascal dialects
Pascal was standardised, extended, and reimplemented many times. The table lists the versions a modern reader is likely to meet. They are not identical: a program written for one dialect may use syntax that another rejects, and the same type name can have a different size.
| Dialect | Year | Character |
|---|---|---|
| ISO Pascal | 1983 | the standard language, ISO 7185 |
| Extended Pascal | 1991 | ISO 10206, with modules and schemata |
| Turbo Pascal | 1983 | the fast MS-DOS compiler that made Pascal popular |
| Delphi | 1995 | Object Pascal with a visual component library |
| Free Pascal | 2000 | a portable open-source compiler with several dialects |
| ObjFPC | 2000s | Free Pascal's Delphi-compatible object mode |
Turbo Pascal, written by Anders Hejlsberg at Borland, was the decisive product for personal computers. It compiled in seconds, ran in a few hundred kilobytes, and shipped with an integrated editor. Delphi added classes, properties, exceptions, and a rapid application development environment. Free Pascal, started in 1993 and released as version 1.0 in 2000, reimplemented the language for many processors and operating systems and supports the Turbo Pascal, FPC, ObjFPC, and Delphi modes.
This series uses Free Pascal 3.2.2 in ObjFPC mode.
ObjFPC is the closest Free Pascal mode to Delphi: classes, interfaces,
properties, exceptions, generics, and units all work, while the compiler remains
an ordinary command-line program. Every source file starts with the same two
directives, which select the mode and make string an
AnsiString:
{$mode objfpc}{$H+}
The first directive is a compiler switch, not a statement. It belongs near the
top of the file, before the declarations that depend on it. The second one is the short
string switch; without it, string would be a ShortString
with a maximum length of 255 characters. The
program structure article explains
both directives in detail.
Installing Free Pascal
Free Pascal is available for Linux, Windows, macOS, and several other systems.
On Debian and Ubuntu the compiler is installed from the fpc
package, which pulls in the compiler, the run-time library, and the standard
units. The installation needs administrator rights.
$ sudo apt install fpc $ fpc -iV $ fpc -iTO $ fpc -iTP
The -i options print information instead of compiling:
-iV is the compiler version, -iTO the target operating
system, and -iTP the target processor. The values below come from
the installation used for this series. A different machine may report a
different processor, and a newer package may report a newer version.
$ fpc -iV 3.2.2 $ fpc -iTO linux $ fpc -iTP x86_64
The first program
The fpc command is a driver: it reads the source file, calls the
compiler and the linker, and leaves an executable in the current directory.
The compiler itself is a separate program, and the driver chooses it from the
target processor. A Pascal program starts with the keyword program
and a name. The
name is followed by a semicolon, and the program ends with the keyword
end and a full stop. The statements between begin
and end are executed in order. Output goes to the screen with
WriteLn, which writes its arguments and then starts a new line.
program hello;
{$mode objfpc}{$H+}
begin
WriteLn('Hello, Pascal!');
end.
The text between single quotes is a string literal. The semicolon separates
the program header from the block, and another one separates the
WriteLn call from end. The final full stop, not a
semicolon, marks the end of the program. Pascal is compiled ahead of time, so
the source file is first translated into an executable and then run. The
-gl option adds line information to the executable, which makes
run-time errors point to the source line. The compiler prints its banner and a
short summary while it works; those lines are omitted here and in the rest of
the series. The executable is named after the source file, without the
extension, and is started with ./hello on Linux.
$ fpc -gl hello.pas $ ./hello Hello, Pascal!
The WriteLn statement
WriteLn accepts any number of arguments, separated by commas, and
writes them one after another. Strings are written as they are, integers in
decimal, and Booleans as TRUE or FALSE. Unlike
Fortran's list-directed output, Pascal does not insert a separator between the
arguments, so spaces must be part of the literals or added explicitly.
program printing;
{$mode objfpc}{$H+}
begin
WriteLn('Value: ', 42);
WriteLn('a', 'b');
WriteLn('a ', 'b');
WriteLn('It''s');
WriteLn('Value:', 42:5);
WriteLn(True);
Write('no newline');
WriteLn;
end.
The first statement prints a label and a number with no padding. The next two
show why the space matters: 'a', 'b' produces ab,
while 'a ', 'b' produces a b. A quote inside a string
is written twice, as in 'It''s'. The field width after the colon
in 42:5 right-aligns the number in five characters, and
Write without Ln leaves the cursor on the same line;
the empty WriteLn then ends that line. The last line of the output
therefore contains the text written by Write followed by the
newline from the empty WriteLn. A real number would print in
scientific notation by default, which is why the next section formats the area
explicitly.
$ fpc -gl printing.pas $ ./printing Value: 42 ab a b It's Value: 42 TRUE no newline
Variables and arithmetic
A variable is declared in a var section, with a name and a type.
The assignment operator is :=, not =; the equals sign
is used for comparisons. A named constant is declared in a const
section. The next program computes the area of a circle from its radius.
program circle;
{$mode objfpc}{$H+}
uses SysUtils;
const
Pi = 3.14159265;
var
r, area: Double;
begin
r := 2.5;
area := Pi * Sqr(r);
WriteLn('Radius: ', r:0:1);
WriteLn('Area: ', area:0:3);
WriteLn(Format('Area: %.3f', [area]));
end.
The uses SysUtils clause makes the Format function
available. Sqr(r) returns r squared, and the two colons in
r:0:1 mean "use the default total width and show one decimal
place". Format is the string-formatting function from
SysUtils; its first argument is a template and the second is an
array of values. The template %.3f prints a fixed-point number
with three decimals. Both output lines show the same value: the first uses the
width-and-precision syntax of WriteLn, the second uses
Format. The literals and
numeric functions articles return to
these forms.
$ fpc -gl circle.pas $ ./circle Radius: 2.5 Area: 19.635 Area: 19.635
Compiler options
The fpc driver accepts many options. The ones below are used in
this series; most programs need only -gl, and the checking options
appear in the articles that demonstrate them. A boolean option is enabled with
a plus sign and disabled with a minus sign, so -Cr enables range
checking and -Cr- disables it.
| Option | Meaning |
|---|---|
-gl | add line information for run-time errors and the debugger |
-Cr | check array bounds and subrange assignments |
-Co | check integer overflow |
-Sa | enable assertions |
-gh | link the heap trace unit and report memory leaks |
-O- | disable optimisation; Free Pascal has no -O0 |
-Sh | use AnsiString for string |
-Mobjfpc | select ObjFPC mode from the command line |
Range and overflow checks are off by default because they make the program slower. During development they are worth the cost: an out-of-bounds array write stops with runtime error 201 instead of corrupting memory, and an overflowing integer stops with runtime error 215 instead of silently wrapping. The program structure article shows how the same checks can be switched on inside the source with directives.
Source files and extensions
Free Pascal recognises several source-file extensions. The examples in this
series use .pas, which is the usual extension for both programs
and units. The other extensions are accepted for compatibility with Lazarus
and Delphi, and an include file is pulled into a source file with a compiler
directive rather than compiled on its own.
| Extension | Used for |
|---|---|
.pas | a program or a unit |
.pp | a program or a unit, the usual Free Pascal source extension |
.lpr | a Lazarus program |
.dpr | a Delphi program |
.inc | an include file, inserted with {$I file.inc} |
The compiler does not require the program name to match the file name. It does
require the file to contain a complete program or unit, and it uses the file
name to derive the name of the executable. An include file contains only
declarations or statements, never program or end.,
because it is inserted in the middle of another file.
Next steps
The program structure article describes the parts of a program, the order of the declaration sections, comments, semicolons, and compiler directives. The variables article covers declarations and constants, data types describes the integer, real, Boolean, character, and string types, and literals and constants shows how values are written in the source text. From there the series continues with operators and expressions, conditionals, loops, numeric functions, and procedures and functions.
Source
In this article we have introduced Pascal, followed it from Wirth's first compiler through Turbo Pascal, Delphi, and Free Pascal, installed Free Pascal 3.2.2, and compiled the first programs. The series continues with Pascal program structure.
Author
List all Pascal tutorials.