Monday, April 25, 2011

Pascal Programming Language and Turbo Pascal



Historically, Pascal was developed by Niklaus Wirth (a Swiss computer scientist) in the early 1970s and was named after the French mathematician Blaise Pascal (1623-1662). A standard for the language was formulated in 1983 and approved by the Institute of Electrical and Electronic Engineers (IEEE) and the American National Standards Institute (ANSI). With the growing use of personal computers, extensions and variations have been added to the language, the most popular of which are UCSD Pascal (developed by University of California at San Diego) and Turbo Pascal Compiler (developed by Borland International).

The Pascal program may be as simple as the one in Example below. It displays on your screen the phrase "Hi there."

(* ----------------------------- Pascal Example ------------------------------ *)

Program FirstProgram (Output);

begin

Writeln ('Hi there')

end.

Whether the Pascal program is small or large, it must have a specific structure. This program consists mainly of one statement (WRITELN) which does the actual work here, as it writes whatever comes between the parentheses. The statement is included inside a frame starting with the keyword BEGIN and ending with the keyword END. This is called the program main body (or the program block) and usually contains the main logic of data processing.

Consider the first line in the program:

(* ----------------------------- Pascal Example ------------------------------ *)

This is a comment and is totally ignored by the compiler. Comments can appear anywhere in the Pascal program between two curly braces or between the two symbols (* and *) thus:

(* This is a comment *)

Program Heading

The second line is called the program heading. It starts with the keyword PROGRAM followed by a space, followed by the program name (FirstProgram). The program name is a user-invented word. User-invented words are classified in Pascal as identifiers. An identifier must begin with a letter and may contain any number of letters or digits (in Turbo Pascal it may contain underscores as well). You are free to choose any meaningful name for your program, but do not expect a program name like "BEGIN" or "PROGRAM" to be accepted. These words are called reserved words, and they are only used in the proper place in the program.

The program name is followed by the word OUTPUT contained in parentheses and terminated with a semicolon:

Program FirstProgram (Output);

The keyword OUTPUT tells the compiler that this program is going to produce output (such as writing to the screen), which is the counterpart of INPUT (such as reading from the keyboard). The words OUTPUT and INPUT are called file parameters. The program may perform both input and output, in which case the file parameters take the form:

Program FirstProgram (Input, Output);

In Turbo Pascal the program heading is optional. You may skip the whole line and start your program with the word BEGIN, or you may use the program name without parameters, like this:

Program FirstProgram;

This is just a simple example of how the Pascal program looks like. Object Pascal is also the language of Delphi - a popular Rapid Application Development environment. There are also Pascal compilers for other processors like Turbo51 which compiles for 8051 microcontrollers.

To know more about the language and to learn the tips and tricks you need some good Pascal book and a lot of practice. Programming is the best way to learn the language and get experience.



No comments:

Post a Comment