
- Order:
- Duration: 7:29
- Published: 2009-09-08
- Uploaded: 2011-01-29
- Author: RenegadeThinking
these configurations will be saved for each time you visit this page using this browser
Name | Pascal |
---|---|
Paradigm | imperative, structured |
Typing | static, strong, safe |
Implementations | CDC 6000, ICT 1900, Pascal-P, PDP-11, PDP-10, IBM System/370, HP, GNU |
Dialects | UCSD, Borland, Turbo |
Year | 1970, last revised 1992 |
Designer | Niklaus Wirth |
Influenced by | ALGOL |
Influenced | Modula, Modula-2, Oberon, Oberon-2, Component Pascal, Ada, Object Pascal, Java, Oxygene |
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 structured programming and data structuring.
A derivative known as Object Pascal was designed for object-oriented programming.
Prior to his work on Pascal, Wirth had developed Euler and Algol-W and later went on to develop the Pascal-like languages Modula-2 and Oberon.
Initially, Pascal was largely, but not exclusively, intended to teach students structured programming. A generation of students used 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).
Object Pascal is still widely used for developing Windows applications such as Skype.
Pascal, like many programming 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.)
The first successful port of the CDC Pascal compiler to another mainframe was completed by Welsh and Quinn at the QUB in 1972. The target was the ICL 1900 series. This compiler in turn was the parent of the Pascal compiler for the ICS Multum minicomputer. The Multum port was developed – with a view to using Pascal as a systems programming language – by Findlay, Cupples, Cavouras and Davis, working at the Department of Computing Science in Glasgow University. It is thought that Multum Pascal, which was completed in the summer of 1973, may have been the first 16-bit implementation.
A completely new compiler was completed by Welsh et al. at QUB in 1977. It offered a source-language diagnostic feature (incorporating profiling, tracing and type-aware formatted postmortem dumps) that was implemented by Findlay and Watt at Glasgow University. This implementation was ported in 1980 to the ICL 2900 series by a team based at Southampton University and Glasgow University. The Standard Pascal Model Implementation was also based on this compiler, having been adapted, by Welsh and Hay at Manchester University in 1984, to check rigorously for conformity to the BSI 6192/ISO 7185 Standard and to generate code for a portable abstract machine.
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.
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. The P-system compilers were termed Pascal-P1, Pascal-P2, Pascal-P3, and Pascal-P4, with Pascal-P1 being the first version, and Pascal-P4 being the last to come from Zurich.
The Pascal-P4 compiler/interpreter can still be run and compiled on systems compatible with original Pascal. However, it only accepts a subset of the Pascal language.
Pascal-P5, created outside of the Zurich group, accepts the full Pascal language and includes ISO 7185 compatibility.
UCSD Pascal branched off Pascal-P2, where Kenneth Bowels utilized it to create the interpretive UCSD p-System
A compiler based on the Pascal-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.
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, and fast turnaround-time (just seconds to compile, link, and run.) 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. At the same time Microsoft also implemented Object Pascal compiler. The Turbo Pascal 5.5 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.) The first versions of the Delphi Programming Language were accordingly named Object Pascal. The main additions compared to the older OOP extensions were a reference-based object model, virtual constructors and destructors, and properties. Several other compilers also implement this dialect.
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.
Here is an example of the source code in use for a very simple "Hello world" program:
{| class="wikitable" border="1" |- ! Data type ! Type of values which the variable is capable of storing |- | integer | Whole numbers |- | real | Floating point numbers |- | boolean | The value TRUE or FALSE |- | char | A single character from an ordered character set |}
The range of values allowed for each (except boolean) is implementation defined. Functions are provided for some data conversions. For conversion of real
to integer
, the following functions are available: round
, which round to integer using banker's rounding; trunc
, round towards zero.
The programmer has the freedom to define other commonly-used data types (e.g. byte, string, etc.) in terms of the predefined types using Pascal's type declaration facility. e.g.
A set is a fundamental concept for modern mathematics, and they may be used in a many algorithms. Such a feature is useful and may be faster than an equivalent construct in a language that does not support sets. For example, for many Pascal compilers:
executes faster than:
Sets of non-contiguous values can be particularly useful, in terms of both performance and readability:
For these examples, which involve sets over small domains, the improved performance is usually achieved by the compiler representing set variables as bitmasks. The set operators can then be implemented efficiently as bitwise machine code operations.
Further, complex types can be constructed from simple types:
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.
Here the variable ptoNode is a pointer to the data type Node, 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:
... ptoNode^.a := 10; ptoNode^.b := 'A'; ptoNode^.c := nil; ...
This could also be done using the with statement, as follows
... with ptoNode^ do begin a := 10; b := 'A'; c := nil end; ...
Inside of the scope of the with statement, a and b refer to the subfields of the record pointer ptoNode and not to the record Node or the pointer type Nodeptr.
Linked lists, stacks and queues can be created by including a pointer type field (c) in the record (see also nil).
Unlike many languages that feature pointers, Pascal only allows pointers to reference dynamically created variables that are anonymous, and does not allow them to reference standard static or local variables. Pointers also must have an associated type, and a pointer to one type is not compatible with a pointer to another type (e.g. a pointer to a char is not compatible with a pointer to an integer). This helps eliminate the type security issues inherent with other pointer implementations, particularly those used for PL/I or C. It also removes some risks caused by dangling pointers, but the ability to dynamically let go of referenced space by using the dispose function (which has the same effect as the free library function found in C) means that the risk of dangling pointers has not been entirely eliminated.
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;
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 (such as Borland Delphi) the strict ordering requirement of declaration sections has been relaxed.
The presence of an extra semicolon was not permitted in early versions of Pascal. However, the addition of ALGOL-like empty statements in the 1973 Revised Report and later changes to the language in ISO 7185:1983 now allow for optional semicolons in most of these cases. The exception is that a semicolon is still not permitted immediately before the else keyword in an if statement.
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. This addition was made at the request of C. A. R. Hoare, and with the approval of Niklaus Wirth. The precipitating cause was that Hoare wanted to create a Pascal version of the (NAG) Numerical Algorithms Library, which had originally been written in FORTRAN, and found that it was not possible to do so without an extension that would allow array parameters of varying size. Similar considerations motivated the inclusion in ISO 7185 of the facility to specify the parameter types of procedural and functional parameters.
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 Borland's dialect.
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.
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).
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.
Category:Articles with example Pascal code Category:1970 introductions Category:Educational programming languages
This text is licensed under the Creative Commons CC-BY-SA License. This text was originally published on Wikipedia and was developed by the Wikipedia community.