Lecture 4: Introduction to PASCAL


PASCAL is a french acronym for "Program Appliqué à la Selection et la Compilation Automatique de la Literature" a high-level ("fourth generation") computer-programming language. Designed by Niklaus Wirth in the 1960s as an aid to teaching programming. It is still widely used as such in universities, and as a good general-purpose programming language. Most professional programmers, however, now use C or C++. Pascal was named after the 17th century French mathematician Blaise Pascal.
Blaise Pascal (1623-1662)

French philosopher and mathematician. He contributed to the development of hydraulics,
the calculus, and the mathematical theory of probability.
His most famous invention was probably the "Pascal Triangle":
Each number is the sum of the two numbers immediately above it, left and right, like this:
      1 1
     1 2 1
    1 3 3 1
   1 4 6 4 1


A program is a sequence of instructions, or statements which inform the computer of a specific task we want it to do.
Most modern program languages are in a very readible format, close to English, making it easy for humans to read and write programs. This in contrast to earlier programming languages, which were closer to things the computer understand. See for example the assembler language (aula 2). PASCAL is the language which most resembles a natural human language and as such is best suited for explaining the art of programming.

Every PASCAL program has the same essential format, (called the template):


Let's take a look at this program.


Identifiers, as the name already says, are used for identifying things. This can be name of programs (as above), name of procedures and functions and names of variables and constants. This we will see in later aulas. Like in most languages, names of identifiers have some restrictions:

Structured programming

The most important thing in programming is to write clear, logical and structured programs.

Reserved keywords in Turbo Pascal

The following words cannot be used for identifiers. Most of these keyword are explained in the lectures in the chapters described by the subject in the second column.
 and  boolean algebra
 array  arrays
 begin  introduction
 case  if .. then
 const  variables and constants
 div  algebra
 do  loops
 downto  loops
 else  if .. then
 end  introduction
 for  loops
 function  procedures and functions
 if  if .. then
 mod  algebra
 nil  pointers
 not  boolean algebra
 of  if .. then
 or  boolean algebra
 procedure  procedures and fucntions
 program  introduction
 record  records
 repeat  loops
 string  variables
 then  if .. then
 to  loops
 type  variables
 until  loops
 var  variables
 while  loops
 with  records
 xor  boolean algebra

The following words are related to variables and constants. Use of these words for identifiers is disadvised:

Quick test:

To test your knowledge of what you have learned in this lesson, click here for an on-line test. Note that this NOT the form the final test takes!

Peter Stallinga. Universidade do Algarve, 17 fevereiro 2002