Pascal (programming language): Difference between revisions
→Compilers: typos corrected |
|||
Line 121: | Line 121: | ||
'''program''' mine(output); |
'''program''' mine(output); |
||
var i : integer; |
|||
'''procedure''' print('''var''' i: integer); |
'''procedure''' print('''var''' i: integer); |
||
Revision as of 19:45, 25 March 2006
Pascal is an imperative computer programming language, developed in 1970 by Niklaus Wirth as a language particularly suitable for structured programming.
History
Pascal is based on the ALGOL programming language and named in honor of mathematician and philosopher Blaise Pascal. Wirth also developed Modula-2 and Oberon, languages similar to Pascal. Oberon also supports object-oriented programming.
Initially, Pascal was a language intended to teach students structured programming, and generations of students have "cut their teeth" on Pascal as an introductory language in undergraduate courses. Variants of Pascal are still widely used today, for example Free Pascal can be used in both 32 and 64 bit formats, and all types of Pascal programs can be used for both education and software development.
Parts of the original Macintosh operating system were written in Pascal and Motorola 68000 assembly language (though later versions incorporated substantial amounts of C++ as well), and the most frequent high-level language used for development in the early Mac community was Pascal. In addition, the popular typesetting system TeX was written by Donald E. Knuth in WEB, a variant of Pascal designed for literate programming.
Implementations
The first Pascal compiler was designed in Zurich for the CDC 6000 computer family, and it became operational in 1970.
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 for a "virtual" machine code (or more properly an intermediate code), and a simulator for that same code. This became the P-system. Although this system was intended to enable true machine code compilers to be created, at least one system, the notable UCSD implementation, utilized it to create an interpretive system UCSD p-System. The P-system compilers were termed P1-P4, with P1 being the first version, and P4 being the last.
Watcom Pascal was developed for the IBM mainframe in the early 1980s.
IP Pascal was an implementation of the Pascal programming language using Micropolis DOS, but was moved rapidly to CP/M running on the Z80.
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.
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 in part to having one of the first full-screen Integrated development environments.
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.
Super Pascal was a variant which added non-numeric labels, a return statement and expressions as names of types.
With Turbo Pascal version 5.5 Borland added object orientation to Pascal.
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. 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 Delphi programming language.
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.
Syntax
Pascal, in its original form, is a purely procedural language with the standard array of if
, while
, for
, and related constructs.
Hello world
All Pascal programs start with the "Program" keyword, an optional list of external file descriptors and then a block of code is indicated with the "Begin
" and "End
" keywords. Semicolons separate statements, and the full stop ends the program (or unit). Letter case is ignored in Pascal source.
program HelloWorld(output);
begin writeln('Hello, World!') end.
Data structures
Pascal has integer, character and boolean as the simple types, plus enumerations, a new type introduced with Pascal.
program myprog; var a: integer; b: char; c: boolean; d: (one, two, three, four, five);
A "subrange" of any of the above types can be made.
var x: 1..10; y: 'a'..'z'; z: two..four;
Types can be built from other types by the type declaration.
program myotherprog; type x = integer; y = x; ...
Further, complex types can be constructed from simple types:
type a = array [1..10] of integer; b = record a: integer; b: char end; c = file of a;
Strings are packed arrays that start with an integer index of 1.
Pointers
Pascal supports the use of pointers:
type a = ^b; b = record a: integer; b: char; c: a end;
var pb: a
Here the variable pb is a pointer to the data type b, a record. To create a new record and assign the values 10 and A to the fields a and b in the record, the commands would be;
new(pb); pb^.a := 10; pb^.b := 'A'; pb^.c := nil; ...
Linked lists can be created by including a pointer type field (c) in the record (see also nil and null (computer)).
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 false'); for i := 1 to 10 do writeln('Iteration: ', i:1); repeat a := a + 1 until a = 10;
Procedures and functions
Pascal structures programs into procedures and functions.
program mine(output); var i : integer; procedure print(var i: integer); function next(i: integer): integer; begin next := i + 1 end; begin writeln('The total is: ', i); i := next(i) 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 block can have its own declarations of goto labels, constants, types, variables, and other procedures and functions, which must all be in that order.
Resources
Compilers
Several Pascal compilers are available for the use of general public:
- Delphi is Borland's 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 and 2006 also support compiling to the .NET platform.
- Free Pascal (www.freepascal.org) is a multi-platform cross-compiler written in Pascal (so that it compiles itself). It is aimed at providing a convenient and powerful compiler, able both to compile legacy applications and to be the means of develop new ones. Also distributed freely under the GNU GPL. It can mix Standard Pascal, Extended Pascal (Turbo Pascal) and Object Pascal (Delphi) code together, and supports a ton of platforms and operating systems. It has recently become a worthy competitor to even the GNU C Compiler due to its platform availability, fast compile time and performance.
- Lazarus is an open source, cross platform, RAD IDE suite modeled after the original versions of Delphi. Lazarus uses Free Pascal as its core compiler while implementing its own LCL (Lazarus Component Library) based on Delphi's VCL (Visual Component Library) concept. It is an up-and-coming Enterprise tool growing much popularity in the opensource world.
- Chrome (Chrome programming language) (website: www.chromesville.com) is a next generation Visual Studio plugin and stand-alone (in the .NET environment only) compiler for the Object Pascal language with the .NET and Mono Platforms. It was created and is sold by RemObjects Software.
- Kylix is Borland's newest reiteration of the Pascal branch of their products. It is the 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 compiler (but not the library or the IDE) is supposed to become Open Source software some time soon.
- 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 the Borland/Turbo Pascal language largely. Support for Borland Delphi and other language variations is quite limited, yet.
- 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 04 Apr 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 low compilation times. Currently, older versions of Turbo Pascal (up to 5.5) are available for free download from Borland's site (registration required).
- 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.
- IP Pascal Originally a Z80/CP/M Pascal that was ported and recoded for Intel 80386/PC, 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. IP Pascal supports the ISO 7185 standard and upgrades the language logically. For example, original Pascal "padded right" strings are supported and integrated upwards seamlessly into dynamic strings. Standard Pascal static arrays are enhanced with dynamic arrays which are fully downward compatible with static arrays, etc.
- Pocket Studio is a Pascal subset compiler/RAD targeting Palm / MC68xxx with some own extensions to assist interfacing with the Palm OS API.
A very extensive list can be found on Pascaland. The site is in French, but it is basically a list with URLs to compilers, so that does not matter. You may also check out Pascal Central, a Mac centric Pascal info and advocacy site with a rich collection of article archives, plus links to many compilers and tutorials.
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. In 1990, an extended Pascal standard was created as ISO/IEC 10206.
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.
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.
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 several features of the full language out. For example, procedures and functions as parameters, undiscriminated variant records, packing, dispose, interprocedural gotos and other features of the full compiler were left off.
UCSD Pascal, under professor Kenneth Bowles, used the Pascal-P2 kit, and consequentially had several of the same differences with the full Zurich Pascal compiler as the Pascal-P compiler did. UCSD Pascal later was adopted as Apple Pascal, and continued through several versions there.
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 as the UCSD compiler, probably because at that time, UCSD was the most common Pascal system running on Microprocessors.
Criticism
While very popular (although more so in the 1980s and early 1990s than now), early versions of Pascal have been widely criticised for being unsuitable for "serious" use outside of teaching. Brian Kernighan, famed populariser of 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 Mac OS 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 or Borland like, a better eventual outcome than Kernighan foresaw.
Based on his experience with Pascal Niklaus Wirth developed two more programming languages: Modula-2 and Oberon. Although these languages are an improvement upon Pascal, they have yet to meet with the same commercial success.
See also
- ALGOL programming language
- C programming language
- Ada programming language: The United States Department of Defense's successor to Pascal, designed to be more feature-full and powerful
- Delphi programming language:
- Modula programming language: Wirth's successor to Pascal
- Oberon programming language: Wirth's object oriented successor to Modula
- Object Pascal
- Pascal and C: A comparison of Pascal and C.
- IP Pascal: A fully extended Pascal with built in graphical porting platform.
- Chrome programming language: An Object Pascal for the .Net framework.
External links
Reference material
Tutorials
Books
- Kathleen Jensen and Niklaus Wirth: PASCAL - User Manual and Report. Springer-Verlag, 1974, 1985, 1991, ISBN 0-387-97649-3 and ISBN 0-540-97649-3 [1]
- also in N. Wirth, and A. I. Wasserman, ed: Programming Language Design. IEEE Computer Society Press, 1980
Journals
- Niklaus Wirth: The Programming Language Pascal. Acta Informatica, 1, (Jun 1971) 35-63
Resources
- Pascal Central — the one-stop Pascal resource site
- Standard Pascal — Resources and history of original, standard Pascal
Standards
- Pascal standards ISO/IEC 10206: Extended Pascal
- ANSI-ISO Pascal ISO/IEC 7185: PASCAL
History
- N. Wirth, M. Broy, ed, and E. Denert, ed: Pascal and its Successors in Software Pioneers: Contributions to Software Engineering. Springer-Verlag, 2002, ISBN 3-540-43081-4
- N. Wirth: Recollections about the Development of Pascal. ACM SIGPLAN Notices, Volume 28, No 3, March 1993.
- Pascal User's Group Newsletters — An early Pascal history resource that contains many letters from Wirth and others concerning Pascal.
Criticism
Humor
- Real Programmers Don't Use Pascal — a joke about why "real programmers" don't use Pascal