Pascal

What is Pascal?

Pascal is a language high-level developed by Niklaus Wirth in the late 1960s. The language is named after Blaise Pascal, a seventeenth-century French mathematician who constructed one of the first mechanical adding machines.

Pascal is best known for its affinity to structured programming techniques. The nature of the language forces the programmer to design programs methodically and carefully. For this reason, it is a popular teaching language.

 

Introduction

PASCAL is a programming language named after the 17th-century mathematician Blaise Pascal. Pascal provides a teaching language that highlights concepts common to all computer languages, in other words, once you learn PASCAL, most other programming languages are very similar. Standardises the language in such a way that it makes programs easy to write

 

Pascal and C Language

Both C and Pascal are considered High-Level Languages. They use English type statements that are converted to machine statements which are executed by computers. C and Pascal’s programs are simple text files containing program statements. As such, they are created using a text editor. This is called the source program

 

Why Learn Pascal

Despite its fading away as the de facto standard, Pascal is still extremely useful. C and C++ are very symbolic languages. Where Pascal chooses words (e.g. begin-end), C/C++ chooses symbols ({-}). Also, C and C++ are not strongly-typed languages. In Pascal, mixing types often led to an error. In C/C++, nothing would happen. You could even treat pointers as integers and do pointer arithmetic with them. In this way, you could very easily crash your program. When the AP exam switched to C++, only a subset of C++ was adopted. Many features, like arrays, were considered too dangerous, and ETS provided its “safe” version of these features. Java corrects many of these problems of C++ (there are no actual pointers in Java).

Another reason: speed and size. The Borland Pascal compiler is still lightning- fast. Borland has revitalized Pascal for Windows with Delphi, a Rapid-Application-Development environment. Instead of spending several hours writing a user interface for a Windows program in C/C++, you could do it in ten minutes with Delphi’s graphical design tools. You could do the same in Visual BASIC, but Delphi is so much faster than Visual BASIC.

Thus, even after C, C++, and Java took over the programming world, Pascal retains a niche in the market. Much small-scale freeware, shareware, and open-source programs are written in Pascal/Delphi. So enjoy learning it while it lasts. It’s a great introduction to computer programming. It’s not scary like C, dangerous like C++, or abstract like Java. In another twenty years, you’ll be one of the few computer programmers to know and appreciate Pascal

 

Writing Programs

Reserve Words There are some words which have a fixed meaning, and cannot be redefined by the programmer. The list follows. These words identify program sections or program flow control structures

Standard identifiers Standard identifiers have a predefined meaning, but a programmer could override that definition with one of her or his own. While this is possible, it is not advisable, as this reduces “common understanding” of what a programmer was attempting at a given point in a program, making your program less maintainable.

 

Basic Program Components

Every Pascal program has the following three components

Program heading: program identifier(input, output); Note that this is probably the only identifier which you only type so that you can use more of the 64 characters available. So, go ahead, create a descriptive identifier.

Declaration section: var const Things that will be used later on in your program are declared here. Nothing happens here,; you’re just telling Turbo Pascal what you need for later on

Executable section: begin…end. Note that the end is followed by a period. All the statements inbetween

 

Writing Code in Pascal

Executable statement: An executable statement consists of valid identifiers, standard identifiers, reserved words, numbers and/or characters together with appropriate punctuation. In a sense, an executable statement is much like a phrase within a sentence.

Semicolon as a separator: Every executable statement needs to be terminated with a semicolon. There is only one exception to this rule, and that is where the statement is followed by the word END.

Writing style – in my not so humble opinion there are two vital skills in writing style. This first is putting in line breaks! This might sound obvious, but Turbo Pascal does not require executable statements to be seperated by a line break, only by a semi-colon. But stringing lines together obscures them, so (especially since I mark you assignments!) don’t do it!

 

Pascal Compiler

A Pascal compiler is itself a computer program who’s only job is to convert the Pascal program from our form to a form the computer can read and execute. The computer prefers a string of 1’s and 0’s that mean very little to us, but can be very quickly and accurately understood by the computer. The original Pascal program is called the “source code”, and the resulting compiled code produced by the compiler is usually called an “object file”.

One or more object files are combined with predefined libraries by a linker, sometimes called a binder, to produce the final complete file that can be executed by the computer. A library is a collection of pre-compiled “object code” that provides operations that are done repeatedly by many computer programs.