Introduction
Pascal is the language Niklaus Wirth published in 1970, designed for teaching clear, structured programming. It spread on home and office computers through Borland’s Turbo Pascal, released in 1983. Object Pascal added classes to it, and Borland’s Delphi, released in 1995 and now sold by Embarcadero, made Object Pascal a language for Windows applications. Free Pascal and the Lazarus environment are free compilers and tools for the same language, which also build for Linux, macOS and many other systems.
.pas is the general extension, used for programs and units. Free Pascal
also accepts .pp. The main file of a Delphi project is a
.dpr and of a Lazarus project a .lpr; both are ordinary
Pascal programs. A Delphi package source is a .dpk, and an include file may
be a .inc.
.pp is also the extension of Puppet manifests, which have no relation to
Pascal.
The pages in the menu describe the language and its main dialects: ISO 7185 and Extended Pascal, UCSD Pascal, Turbo and Borland Pascal, Delphi and Free Pascal. They follow the Free Pascal Reference guide and Programmer’s guide (version 3.2.2) for the language and the compiler directives, and the Free Pascal compiler’s source for the exact forms of literals and comments.
Structure
A Pascal file is plain text and the language ignores case. A program starts with
program Name;, then a uses clause naming its units, then
const, type and var sections and procedures and
functions. The main block is begin … end., with a full stop
after the last end.
A unit, the language’s module, starts with unit Name;, and has an
interface section of what it exports and an implementation
section with the code. Assignment is :=, equality is =,
<> means not equal and strings use single quotes. Comments are
{ } and (* *), plus // in Delphi and Free Pascal.
Compiler directives are comments starting with a dollar sign, such as
{$mode objfpc}.
program Hello;
{$mode objfpc}
uses
SysUtils;
type
TGreeter = class
Name: string;
function Greeting: string;
end;
function TGreeter.Greeting: string;
begin
Result := 'Hello, ' + Name;
end;
var
G: TGreeter;
begin
G := TGreeter.Create;
G.Name := 'world';
WriteLn(G.Greeting);
G.Free;
end.
Language reference
The reference is split into these pages.
- File structure – programs, units, libraries and packages,
interfaceandimplementation, encodings, extensions and the files that go with Pascal source - Lexical structure – comments and how they nest, identifiers, reserved words and directives, symbols, number and string literals including
#,^and multi-line strings - Compiler directives –
{$…}, modes and mode switches, switches, conditional compilation, macros, includes and resources - Types – integers, booleans, characters, enumerations, reals, strings, arrays, records, sets, files, pointers, procedural and variant types
- Declarations –
label,const,type,var,threadvar,resourcestring, scope and hint directives - Expressions – precedence, operators, casts, constructors and constant expressions
- Statements – assignment,
if,case, loops,with,goto,exit,break - Procedures and functions – parameters, results, directives, calling conventions, overloading, operators
- Classes and objects – objects, classes, visibility, properties, interfaces, records with methods, helpers, attributes
- Generics – generic types and routines, constraints,
specialize, collections, anonymous methods - Exceptions and memory –
try,raise, run-time errors, pointers, the heap and who frees what - Assembler –
asmblocks, syntaxes, registers and inline machine code - Units and libraries –
uses, initialisation order, DLLs, packages, includes, resources - Standard library – the System unit, the main units of Delphi, Free Pascal and Turbo Pascal, and the names the viewer colours
- Dialects and versions – ISO 7185, Extended Pascal, UCSD, Turbo Pascal, Delphi, Free Pascal modes, Oxygene
Not described
Known, not yet covered
- Reference: Embarcadero’s Delphi Language Guide (DocWiki) could not be read by this site’s tools, so the Delphi reserved word and directive lists, the Delphi-only directives and the version history are written from the Free Pascal documentation, the Free Pascal compiler source and general knowledge, and have not been checked against DocWiki. See Lexical structure.
- Reference: the texts of ISO 7185 and ISO/IEC 10206 are paywalled and were not read. The ISO and Extended Pascal rules come from the Free Pascal documentation of its
isoandextendedpascalmodes. - Reference: Extended Pascal’s own features (schema types, modules with
exportandimport, thevalueandonlywords,pow, string and time built-ins) are named but not described. - Viewer: the Extended Pascal reserved words other than
otherwiseandmodule, and the Oxygene keywords other thannamespaceandmethod, are shown plain. - Viewer: code that a conditional directive switches off is coloured like any other code, and a type or class name declared by the program is not coloured as a type.
- Viewer: form description files (
.dfm,.lfm,.fmx) have no viewer of their own.
Unknown
- Viewer: the colouring was checked against real files and the compiler’s source, never against a running compiler, so a rule that depends on a compiler’s mode (nested comments with no
{$mode}line, for example) follows the most common case.
Links
Software
- Free Pascal – free compiler for Pascal and Object Pascal (Windows, macOS, Linux)
- Lazarus – free development environment built on Free Pascal (Windows, macOS, Linux)
- Delphi – Embarcadero’s commercial Object Pascal environment (Windows)
Reference
- Free Pascal documentation – includes the language reference guide
- Embarcadero DocWiki – Delphi’s documentation, with its language guide
- ISO 7185 – the international standard for Pascal
- ISO/IEC 10206 – the standard for Extended Pascal