Pascal
From Compsci.ca Wiki
m |
m (Reverted edit of LzgWlo, changed back to last version by Wtd) |
||
(One intermediate revision not shown) | |||
Line 24: | Line 24: | ||
repeat | repeat | ||
- | a := a | + | a := a + 1; |
until a = 10; | until a = 10; | ||
</pre> | </pre> | ||
Line 37: | Line 37: | ||
Function Bar(a:integer):integer; | Function Bar(a:integer):integer; | ||
Begin | Begin | ||
- | Bar := a | + | Bar := a + 1; |
End; | End; | ||
</pre> | </pre> |
Latest revision as of 00:18, 11 June 2007
Pascal is an imperative computer programming language, developed in 1970 by Niklaus Wirth as a language particularly suitable for structured programming. Pascal is based on the ALGOL programming language and named in honor of mathematician and philosopher Blaise Pascal.
Contents |
Language
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). Upper and lower case are considered to be the same in pascal.
program HelloWorld; begin writeln('Hello, World!'); end.
Pascal is a purely procedural language with the standard array of if
, while
, for
, and related constructs. It is a structured programming language, meaning that the flow of control is structured into standard statements, ideally without 'goto' 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); repeat a := a + 1; until a = 10;
Pascal structures programs into procedures and functions.
Procedure Foo(parameter:integer); Begin Writeln(‘Foo(‘, parameter,’);’); End; Function Bar(a:integer):integer; Begin Bar := a + 1; 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. Depending on the compiler there may be many basic types defined. Usually integer, longint, char, Boolean, and string are defined. Other basic types for floating point might also be defined (float, double, and/or real), as well as larger integer types. Enumerated types are also supported.
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';
Types can be built from other types by the type declaration.
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.
Pascal also 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.
Features
Pascal was originally intended to be a teaching language, so its syntax is relatively easy to learn. Because of its age it lacks support for newer concepts such as classes and objects, however many newer compilers do provide some support for these features. Pascal can be interpreted or compiled directly to machine code, depending on the compiler you are using. Mostly it is just a compiled language.
As pascal was intended to be a teaching language, it contains all the essential programming features -- Input/Output, Control Flow, Iteration, etc. Common tasks (such as receiving keyboard input) are quite simple, allowing students to focus on the logic of the program rather than details about the implementation. In addition, many compilers also provide easy to use graphics libraries so that students don’t need to learn DirectX or OpenGL to do simple drawing; though interfaces to both libraries can usually be found.
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.
Compilers
There are many compilers for pascal, the most notable ones being the Free Pascal compiler, and the GNU Pascal compiler.
Borland also makes pseudo pascal compilers under the names “Turbo Pascal” and “Delphi”, however despite their similarity to pascal, they do not make any effort to be standards compliant.
External Links
Derivatives
Pascal has had enough of an impact on the programming language world that several languages are modelled after it, either in syntax and semantics, and sometimes both. Some of these languages in fact have been developed by Niklaus Wirth as successors to Pascal.