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.
.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.
.pp is also the extension of Puppet manifests, which have no relation to
Pascal.
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.
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