Definitions

compas pascal

Pascal (programming language)

Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using so-called structured programming and data structuring.

A derivative known as Object Pascal was designed for object oriented programming. Sometimes it is also referred to as Pascal for simplicity.

History

Pascal is based on the ALGOL programming language and named in honor of the French mathematician and philosopher Blaise Pascal. Wirth subsequently developed the Modula-2 and Oberon, languages similar to Pascal, and earlier, also the language Euler.

Initially, Pascal was largely, but not exclusively, intended to teach students structured programming. Generations of students have "cut their teeth" on Pascal as an introductory language in undergraduate courses. Variants of Pascal have also frequently been used for everything from research projects to PC games and embedded systems. Newer Pascal compilers exist which are widely used.

Pascal was the primary high-level language used for development in the Apple Lisa, and in the early years of the Mac; parts of the original Macintosh operating system were hand-translated into Motorola 68000 assembly language from the Pascal sources. The popular typesetting system TeX by Donald E. Knuth was written in WEB, the original literate programming system, based on DEC PDP-10 Pascal, while an application like Total Commander was written in Delphi (i.e. Object Pascal).

Brief description

Wirth's intention was to create an efficient language (regarding both compilation speed and generated code) based on so-called structured programming, a concept which had recently become popular. Pascal has its roots in the Algol 60 language, but also introduced concepts and mechanisms which (on top of Algol's scalars and arrays) enabled programmers to define their own complex (structured) datatypes, and also made it easier to build dynamic and recursive data structures such as lists, trees and graphs. Important features included for this were records, enumerations, subranges, dynamically allocated variables with associated pointers, and sets. To make this possible and meaningful, Pascal has a strong typing on all objects, which means that one type of data cannot be converted or interpreted as another without explicit conversions. Similar mechanisms are standard in many programming languages today. Other languages that influenced Pascal's development were COBOL, ALGOL 68, Simula 67, and Wirth's own Algol-W .

Pascal, like many scripting languages of today (but unlike most languages in the C-family), allows nested procedure definitions to any level of depth, and also allows most kinds of definitions and declarations inside procedures and functions. This enables a very simple and coherent syntax where a complete program is syntactically nearly identical to a single procedure or function (except for the keyword itself, of course).

Implementations

The first Pascal compiler was designed in Zurich for the CDC 6000 series mainframe computer family. Niklaus Wirth reports that a first attempt to implement it in Fortran in 1969 was unsuccessful due to Fortran's inadequacy to express complex data structures. The second attempt was formulated in the Pascal language itself and was operational by mid-1970. Many Pascal compilers since have been similarly self-hosting, that is, the compiler is itself written in Pascal, and the compiler is usually capable of recompiling itself when new features are added to the language, or when the compiler is to be ported to a new environment. The GNU Pascal compiler is one notable exception, being written in C.

The first successful port of the CDC Pascal compiler to another mainframe was completed by Welsh and Quinn at the Queen's University of Belfast in 1972. The target was the ICL 1900 computer.

The first Pascal compiler written in North America was constructed at the University of Illinois under Donald B. Gillies for the PDP-11 and generated native machine code. Pascal enjoyed great popularity throughout the 1970s and the 1980s.

In order to rapidly propagate the language, a compiler "porting kit" was created in Zurich that included a compiler that generated code for a "virtual" stack machine (i.e. code that lends itself to reasonably efficient interpretation), along with an interpreter for that code - the Pascal-P system. Although the SC (Stack Computer) code was primarily intended to be compiled into true machine code, at least one system, the notable UCSD implementation, utilized it to create the interpretive UCSD p-System. The P-system compilers were termed P1-P4, with P1 being the first version, and P4 being the last to come from Zurich.

The P4 compiler/interpreter can still be run and compiled on systems compatible with original Pascal. However, it only itself accepts a subset of the Pascal language. A version of P4 that accepts the full Pascal language and includes ISO 7185 compatibility was created and termed the P5 compiler, which is available in source form. An alternative version known as the "model implementation" of Pascal also accepts and is written in ISO 7185, but is not available in computer readable form.

A version of the P4 compiler, which created native binaries, was released for the IBM System/370 mainframe computer by the Australian Atomic Energy Commission; it was called the "AAEC Pascal Compiler" after the abbreviation of the name of the Commission. A version of P4 from 1975-6 including source and binaries for the compiler and run-time library files for the PDP-10 mainframe may be downloaded from this link

In the early 1980s, Watcom Pascal was developed, also for the IBM System 370.

IP Pascal was an implementation of the Pascal programming language using Micropolis DOS, but was moved rapidly to CP/M running on the Z80. It was moved to the 80386 machine types in 1994, and exists today as Windows/XP and Linux implementations. In 2008, the system was brought up to a new level and the resulting language termed "Pascaline" (after Pascal's calculator). It includes objects, namespace controls, dynamic arrays, along with many other extensions, and generally features the same functionality and type protection as C#. It is the only such implementation which is also compatible with the original Pascal implementation (which is standardized as ISO 7185).

In the early 1980s, UCSD Pascal was ported to the Apple II and Apple III computers to provide a structured alternative to the BASIC interpreters that came with the machines.

Apple Computer created its own Lisa Pascal for the Lisa Workshop in 1982 and ported this compiler to the Apple Macintosh and MPW in 1985. In 1985 Larry Tesler, in consultation with Niklaus Wirth, defined Object Pascal and these extensions were incorporated in both the Lisa Pascal and Mac Pascal compilers.

In the 1980s Anders Hejlsberg wrote the Blue Label Pascal compiler for the Nascom-2. A reimplementation of this compiler for the IBM PC was marketed under the names Compas Pascal and PolyPascal before it was acquired by Borland. Renamed to Turbo Pascal it became hugely popular, thanks in part to an aggressive pricing strategy and in part to having one of the first full-screen Integrated development environments. Additionally, it was written and highly optimized entirely in assembly language, making it smaller and faster than much of the competition. In 1986 Anders ported Turbo Pascal to the Macintosh and incorporated Apple's Object Pascal extensions into Turbo Pascal. These extensions were then added back into the PC version of Turbo Pascal for version 5.5.

The inexpensive Borland compiler had a large influence on the Pascal community that began concentrating mainly on the IBM PC in the late 1980s. Many PC hobbyists in search of a structured replacement for BASIC used this product. It also began adoption by professional developers. Around the same time a number of concepts were imported from C in order to let Pascal programmers use the C-based API of Microsoft Windows directly. These extensions included null-terminated strings, pointer arithmetic, function pointers, an address-of operator and unsafe typecasts.

However, Borland later decided it wanted more elaborate object-oriented features, and started over in Delphi using the Object Pascal draft standard proposed by Apple as a basis. (This Apple draft is still not a formal standard.) Borland also called this Object Pascal in the first Delphi versions, but changed the name to Delphi Programming Language in later versions, see Borland Delphi. The main additions compared to the older OOP extensions were a reference-based object model, virtual constructors and destructors, and properties. There are several other compilers implementing this dialect, see Object Pascal.

Turbo Pascal, and other derivatives with units or module concepts are modular languages. However, it does not provide a nested module concept or qualified import and export of specific symbols.

Super Pascal was a variant which added non-numeric labels, a return statement and expressions as names of types.

The universities of Zurich, Karlsruhe and Wuppertal have developed an EXtension for Scientific Computing (Pascal XSC), which provides a free solution for programming numerical computations with controlled precision.

In 2005, at the Web 2.0 conference, Morfik Technology introduced a tool which allowed the development of Web applications entirely written in Morfik Pascal. Morfik Pascal is a dialect of Object Pascal, very close to Delphi.

Language constructs

Pascal, in its original form, is a purely procedural language and includes the traditional array of Algol-like control structures with reserved words such as if, then, else, while, for, and so on. However, Pascal also has many data structuring facilities and other abstractions which were not included in the original Algol60, like type definitions, records, pointers, enumerations, and sets. Such constructs were in part inherited or inspired from Simula67, Algol68, Niklaus Wirth's own AlgolW and suggestions by C. A. R. Hoare.

Hello world

Pascal programs start with the program keyword with a list of external file descriptors as parameters; then follows the main statement block encapsulated by the begin and end keywords. Semicolons separate statements, and the full stop ends the whole program (or unit). Letter case is ignored in Pascal source. Some compilers, Turbo Pascal among them, have made the program keyword optional.

Here is an example of the source code in use for a very simple program:

Program HelloWorld(output); begin

 writeLn('Hello, World!')
end.

Data types

A type in Pascal, and in several other popular programming languages, defines a variable in such a way that it defines a range of values which the variable is capable of storing, and it also defines a set of operations that are permissible to be performed on variables of that type. TURBO Pascal has eight basic data types which are predefined and can be used anywhere in a program provided you use them properly. This chapter is devoted to illustrating the use of these eight data types by defining the allowable range of values that can be assigned to them, and by illustrating the operations that can be done to variables of these types. The eight types and a very brief description follows;

Data type Range of values which the variable is capable of storing
integer Whole numbers from -32768 to 32767
byte The integers from 0 to 255
real Floating point numbers from 1E-38 to 1E+38
boolean Can only have the value TRUE or FALSE
char Any character in the ASCII character set
shortint The integers from -128 to 127
word The integers from 0 to 65535
longint The integers from -2147483648 to 2147483647
Please note that four of these types of data (char, shortint, word, and longint) are not a part of the standard Pascal definition but are included as extensions to the TURBO Pascal compiler.

In addition to the above data types TURBO Pascal version 5.0 and later have the following data types available:

Data type Range of values which the variable is capable of storing
single Real type with 7 significant digits
double Real type with 15 significant digits
extended Real type with 19 significant digits
comp The integers from about -10E18 to 10E18

Data structures

Pascal's simple (atomic) types are real, integer, character, boolean, string and enumerations, a new type constructor introduced with Pascal:

var

 r: Real;
 i: Integer;
 c: Char;
 b: Boolean;
 w: String;
 e: (apple, pear, banana, orange, lemon);

Subranges of any ordinal type (any simple type except real) can be made:

var

 x: 1..10;
 y: 'a'..'z';
 z: pear..orange;

In contrast with other programming languages from its time, Pascal supports a set type:

var

 set1: set of 1..10;
 set2: set of 'a'..'z';
 set3: set of pear..orange;

A set is fundamental concept for modern mathematics, and they may be used in a great many algorithms. Such a feature is highly useful and may be faster than an equivalent construct in a language that does not support sets. For example, for many Pascal compilers:

if i in [5..10] then ...

is faster, than

if (i>4) and (i<11) then ...

Types can be defined from other types using type declarations:

type

 x = Integer;
 y = x;
...

Further, complex types can be constructed from simple types:

type

 a = Array [1..10] of Integer;
 b = record
       x: Integer;
       y: Char
     end;
 c = File of a;

As shown in the example above, Pascal files are sequences of components. Every file has a buffer variable which is denoted by f^. The procedures get (for reading) and put (for writing) move the buffer variable to the next element. Read is introduced such that read(f, x) is the same as x:=f^; get(f);. Write is introduced such that write(f, x) is the same as f^ := x; put(f); The type text is predefined as file of char. While the buffer variable could be used to inspect the next character that would be used (check for a digit before reading an integer), this concept lead to serious problems with interactive programs with early implementations, but was solved later with the "lazy I/O" concept.

In Jensen & Wirth Pascal, strings are represented as packed arrays of chars; they therefore have fixed length and are usually space-padded. Some dialects have a custom string type.

Pointers

Pascal supports the use of pointers:

type

 a = ^b;
 b = record
       a: Integer;
       b: Char;
       c: a
     end;
var
 pointer_to_b: a;

Here the variable pointer_to_b is a pointer to the data type b, a record. Pointers can be used before they are declared. This is a forward declaration, an exception to the rule that things must be declared before they are used. To create a new record and assign the value 10 and character A to the fields a and b in the record, and to initialise the pointer c to nil, the commands would be:

new(pointer_to_b);

pointer_to_b^.a := 10; pointer_to_b^.b := 'A'; pointer_to_b^.c := nil; ...

This could also be done using the with statement, as follows

new(pointer_to_b);

with pointer_to_b^ do begin

 a := 10;
 b := 'A';
 c := nil
end; ...

Note that inside of the scope of the with statement, the compiler knows that a and b refer to the subfields of the record pointer pointer_to_b and not to the record b or the pointer type a.

Linked lists, stacks and queues can be created by including a pointer type field (c) in the record (see also nil and null (computer programming)).

Control structures

Pascal is a structured programming language, meaning that the flow of control is structured into standard statements, ideally without 'go to' commands.

while a <> b do writeln('Waiting');

if a > b then writeln('Condition met') else writeln('Condition not met');

for i := 1 to 10 do writeln('Iteration: ', i:1);

repeat

 a := a + 1
until a = 10;

case i of

 0: write('zero');
 1: write('one');
 2: write('two')
end;

Procedures and functions

Pascal structures programs into procedures and functions.

program mine(output);

var i : integer;

procedure print(var j: integer);

 function next(k: integer): integer;
 begin
   next := k + 1
 end;


begin
 writeln('The total is: ', j);
 j := next(j)
end;

begin
 i := 1;
 while i <= 10 do print(i)
end.

Procedures and functions can nest to any depth, and the 'program' construct is the logical outermost block.

Each procedure or function can have its own declarations of goto labels, constants, types, variables, and other procedures and functions, which must all be in that order. This ordering requirement was originally intended to allow efficient single-pass compilation. However, in some dialects the strict ordering requirement of declaration sections is not required.

Resources

Compilers and interpreters

Several Pascal compilers and interpreters are available for the use of general public:

  • Delphi is CodeGear's (formerly Borland) flagship RAD (Rapid Application Development) product. It uses the Object Pascal language (Dubbed the 'Delphi programming language' by Borland), descended from Pascal, to create applications for the windows platform. The latest versions 2005 to 2007 also support compiling to the .NET platform. A version of Delphi, Turbo Delphi Explorer, is available for free download.
  • Free Pascal (www.freepascal.org) is a multi-platform compiler written in Pascal (it is Self-hosting). It is aimed at providing a convenient and powerful compiler, both able to compile legacy applications and to be the means of developing new ones. It is distributed under the GNU GPL. Apart from compatibility modes for Turbo Pascal, Delphi and Mac Pascal, it also has its own procedural and object oriented syntax modes with support for extended features such as operator overloading. It supports many platforms and operating systems.
  • Dev-Pascal (Dev-Pascal) is a Pascal IDE that was designed in Borland Delphi and which supports both Free Pascal and GNU Pascal as backend. Contrary to its C++ sibling, it has not seen a significant release in years
  • Oxygene (formerly known as Chrome) is a Next Generation Object Pascal compiler for the .NET and Mono Platforms. It was created and is sold by RemObjects Software
  • Kylix was a descendant of Delphi, with support for the Linux operating system and an improved object library. The compiler and the IDE are available now for non-commercial use. The product is no longer supported by Borland.
  • GNU Pascal Compiler (GPC) is the Pascal compiler of the GNU Compiler Collection (GCC). The compiler itself is written in C, the runtime library mostly in Pascal. Distributed freely under the GNU General Public License, it runs on many platforms and operating systems. It supports the ANSI/ISO standard languages and partial Borland/Turbo Pascal language support. One of the more painful omissions is the absence of a 100% TP compatible string type. Support for Borland Delphi and other language variations is quite limited, except maybe for Mac Pascal, the support for which is growing fast.
  • Virtual Pascal was created by Vitaly Miryanov in 1995 as a native OS/2 compiler compatible with Borland Pascal syntax. Then, it had been commercially developed by fPrint, adding Win32 support, and in 2000 it became freeware. Today it can compile for Win32, OS/2 and Linux, and is mostly compatible with Borland Pascal and Delphi. Development on this compiler was canceled on April 4, 2005.
  • P4 compiler, the basis for many subsequent Pascal-implemented-in-Pascal compilers, including the UCSD p-System.
  • Turbo Pascal was the dominant Pascal compiler for PCs during the 80s and early 90s, popular both because of its powerful extensions and extremely short compilation times. Turbo Pascal was compactly written and could compile, run, and debug all from memory without accessing disk. Slow floppy disk drives were common for programmers at the time, further magnifying Turbo Pascal's speed advantage. Currently, older versions of Turbo Pascal (up to 5.5) are available for free download from Borland's site.
  • Turbo51 (turbo51.com) is a free Pascal compiler for the 8051 family of microcontrollers (uses Turbo Pascal 7 syntax)
  • Dr. Pascal is an interpreter that runs Standard Pascal. Notable are the "visible execution" mode that shows a running program and its variables, and the extensive runtime error checking. Runs programs but does not produce a separate executable binary. Runs on MS-DOS, Windows in DOS window, and old Macintosh.
  • Dr. Pascal's Extended Pascal Compiler tested on DOS, Windows 3.1, 95, 98, NT.
  • IP Pascal Implements the language "Pascaline" (named after Pascal's calculator), which is a highly extended Pascal compatible with original Pascal according to ISO 7185. It features modules with namespace control, including parallel tasking modules with semaphores, objects, dynamic arrays of any dimensions that are allocated at runtime, overloads, overrides, and many other extensions. IP Pascal has a built-in portability library that is custom tailored to the Pascal language. For example, a standard text output application from 1970's original Pascal can be recompiled to work in a window and even have graphical constructs added.
  • Pocket Studio is a Pascal subset compiler/RAD targeting Palm / MC68xxx with some own extensions to assist interfacing with the Palm OS API.
  • MIDletPascal - A Pascal compiler and IDE that generates small and fast Java bytecode specifically designed to create software for mobiles
  • Vector Pascal Vector Pascal is a language targeted at SIMD instruction sets such as the MMX and the AMD 3d Now, supporting all Intel and AMD processors, as well as the Sony Playstation 2 Emotion Engine.
  • Morfik Pascal allows the development of Web applications entirely written in Object Pascal (both server and browser side).
  • web Pascal (www.codeide.com) is an online IDE and Pascal compiler.
  • WDSibyl - Visual Development Environment and Pascal compiler for Win32 and OS/2
  • PP Compiler, a compiler for Palm OS that runs directly on the handheld computer

A very extensive list can be found on Pascaland The site is in French, but it is basically a list with URLs to compilers; there is little barrier for non-Francophones. The site, Pascal Central, a Mac centric Pascal info and advocacy site with a rich collection of article archives, plus links to many compilers and tutorials, may also be of interest.

Standards

In 1983, the language was standardized, in the international standard ISO/IEC 7185, as well as several local country specific standards, including the American ANSI/IEEE770X3.97-1983, and ISO 7185:1983. These two standards differed only in that the ISO standard included a "level 1" extension for conformant arrays, where ANSI did not allow for this extension to the original (Wirth version) language. In 1989, ISO 7185 was revised (ISO 7185:1990) to correct various errors and ambiguities found in the original document.

In 1990, an extended Pascal standard was created as ISO/IEC 10206. In 1993 the ANSI standard was replaced by the ANSI organization with a "pointer" to the ISO 7185:1990 standard, effectively ending its status as a different standard.

The ISO 7185 was stated to be a clarification of Wirth's 1974 language as detailed by the User Manual and Report [Jensen and Wirth], but was also notable for adding "Conformant Array Parameters" as a level 1 to the standard, level 0 being Pascal without Conformant Arrays.

Note that Niklaus Wirth himself referred to the 1974 language as "the Standard", for example, to differentiate it from the machine specific features of the CDC 6000 compiler. This language was documented in "The Pascal Report", the second part of the "Pascal users manual and report".

On the large machines (mainframes and minicomputers) Pascal originated on, the standards were generally followed. On the IBM-PC, they were not. On IBM-PCs, the Borland standards Turbo Pascal and Delphi have the greatest number of users. Thus, it is typically important to understand whether a particular implementation corresponds to the original Pascal language, or a Borland dialect of it.

The IBM-PC versions of the language began to differ with the advent of UCSD Pascal, an interpreted implementation that featured several extensions to the language, along with several omissions and changes. Many UCSD language features survive today, including in Borlands dielect.

Divisions

Niklaus Wirth's Zurich version of Pascal was issued outside of ETH in two basic forms, the CDC 6000 compiler source, and a porting kit called Pascal-P system. The Pascal-P compiler left out several features of the full language. For example, procedures and functions used as parameters, undiscriminated variant records, packing, dispose, interprocedural gotos and other features of the full compiler were omitted.

UCSD Pascal, under Professor Kenneth Bowles, was based on the Pascal-P2 kit, and consequently shared several of the Pascal-P language restrictions. UCSD Pascal was later adopted as Apple Pascal, and continued through several versions there. Although UCSD Pascal actually expanded the subset Pascal in the Pascal-P kit by adding back standard Pascal constructs, it was still not a complete standard installation of Pascal.

Borland's Turbo Pascal, written by Anders Hejlsberg was written in assembly language independent of UCSD or the Zurich compilers. However, it adopted much of the same subset and extensions as the UCSD compiler. This is probably because the UCSD system was the most common Pascal system suitable for developing applications on the resource-limited microprocessor systems available at that time.

List of related standards

  • ISO 8651-2:1988 Information processing systems -- Computer graphics -- Graphical Kernel System (GKS) language bindings -- Part 2: Pascal

Reception

Pascal generated a wide variety of responses in the computing community, both critical and complimentary.

Criticism

While very popular (although more so in the 1980s and early 1990s than now), early versions of Pascal have been widely criticized for being unsuitable for "serious" use outside of teaching. Brian Kernighan, who popularized the C programming language, outlined his most notable criticisms of Pascal as early as 1981, in his paper Why Pascal Is Not My Favorite Programming Language On the other hand, many major development efforts in the 1980s, such as for the Apple Lisa and Macintosh, heavily depended on Pascal (to the point where the C interface for the Macintosh operating system API had to deal in Pascal data types).

In the decades since then, Pascal has continued to evolve and most of Kernighan's points do not apply to current implementations. Unfortunately, just as Kernighan predicted in his article, most of the extensions to fix these issues were incompatible from compiler to compiler. In the last decade, however, the varieties seem to have condensed into two categories, ISO and Borland like, a better eventual outcome than Kernighan foresaw.

Although Kernighan decried Pascal's lack of type escapes ("there is no escape" from "Why Pascal is not my Favorite Programming language"), the uncontrolled use of pointers and type escapes have become highly criticized features in their own right, and the languages Java, C# and others feature a sharp turn-around to the Pascal point of view. What these languages call "managed pointers" were in fact foreseen by Wirth with the creation of Pascal.

Based on his experience with Pascal (and earlier with ALGOL) Niklaus Wirth developed several more programming languages: Modula, Modula-2 and Oberon. These languages address some criticisms of Pascal, are intended for different user populations, and so on, but none has had the widespread impact on computer science and computer users as has Pascal, nor has any yet met with similar commercial success.

See also

Further reading

  • Niklaus Wirth: The Programming Language Pascal. 35-63, Acta Informatica, Volume 1, 1971.
  • C A R Hoare: Notes on data structuring. In O-J Dahl, E W Dijkstra and C A R Hoare, editors, Structured Programming, pages 83–174. Academic Press, 1972.
  • C. A. R. Hoare, Niklaus Wirth: An Axiomatic Definition of the Programming Language Pascal. 335-355, Acta Informatica, Volume 2, 1973.
  • Kathleen Jensen and Niklaus Wirth: PASCAL - User Manual and Report. Springer-Verlag, 1974, 1985, 1991, ISBN 0-387-97649-3 and ISBN 3-540-97649-3
  • Niklaus Wirth: Algorithms + Data Structures = Programs. Prentice-Hall, 1975, ISBN 0-13-022418-9
  • Niklaus Wirth: An assessment of the programming language PASCAL 23-30 ACM SIGPLAN Notices Volume 10, Issue 6, June 1975.
  • N. Wirth, and A. I. Wasserman, ed: Programming Language Design. IEEE Computer Society Press, 1980
  • D. W. Barron (Ed.): Pascal - The Language and its Implementation. John Wiley 1981, ISBN 0-471-27835-1
  • Peter Grogono: Programming in Pascal, Revised Edition, Addison-Wesley, 1980
  • Richard S. Forsyth: Pascal in Work and Play, Chapman and Hall, 1982

External links

Search another word or see compas pascalon Dictionary | Thesaurus |Spanish
Copyright © 2014 Dictionary.com, LLC. All rights reserved.
  • Please Login or Sign Up to use the Recent Searches feature