Lecture 4: Introduction to PASCAL


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
     1 2 1
    1 3 3 1
   1 4 6 4 1
 


Start


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):

PROGRAM Title;
begin
  program_statement_1;
  program_statement_2;
         |
  program_statement_n;
end.

Let's take a look at this program.


Identifiers


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.
keyword
subject
 and  boolean algebra
 asm  
 array  arrays
 begin  introduction
 case  if .. then
 const  variables and constants
 constructor  
 destructor  
 div  algebra
 do  loops
 downto  loops
 else  if .. then
 end  introduction
 exports  
 file  
 for  loops
 function  procedures and functions
keyword
subject
 goto  
 if  if .. then
 implementation  
 in  
 inherited  
 inline  
 interface  
 label  
 library  
 mod  algebra
 nil  pointers
 not  boolean algebra
 object  
 of  if .. then
 or  boolean algebra
 packed  
 procedure  procedures and fucntions
keyword
subject
 program  introduction
 record  records
 repeat  loops
 set  
 shl  
 shr  
 string  variables
 then  if .. then
 to  loops
 type  variables
 unit  
 until  loops
 uses  
 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:
 
 boolean 
 byte 
 char 
 double 
 integer 
 real 
 string
 text 
 word
 
 


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