Академический Документы
Профессиональный Документы
Культура Документы
Introduction to Pascal
Programming Language
Learning Outcomes
Upon completion of this lecture, learners will
be able to:
Identify basic Pascal program structure
Recognise important Pascal tokens
Grasp the basis concept of identifiers, constants,
datatypes and variables
Page 2 of 23
Outline
program <program_name>;
Declaration section
var
(* variable declaration
section *)
Body section
Begin
(* program statements *)
End.
Page 5 of 23
Page 6 of 23
Errors in program
Syntax error
Logic error
incorrect translation of either the problem statement or the
algorithm which produce incorrect result
Page 7 of 23
Comments
For the programmer to explain pieces of
code
Compiler will ignore the comments
Comments are discarded by the compiler during
compilation process
Comments are not translated into machine code
Page 8 of 23
..Comments
Page 9 of 23
..Comments
Syntax
(* <comments> *)
{ <comments> }
// <comments>
Example
(* my comments *)
{ my comments }
// my comments
(*********************************
input : radius
process : peri = 2 * PI * radius
output : peri
**********************************)
Page 10 of 23
..Reserved Words
Page 11 of 23
Reserved Words
Belong to Pascal programming language
Mean something to the compiler
Cannot be redefined by programmer
Page 12 of 23
..Reserved Words
Reserved words in free Pascal
Page 13 of 23
Identifiers
Identifiers are all programmer defined names
in program i.e
Constants
Variables
Programs
Functions
Procedures etc.
Page 14 of 23
..Identifiers
Page 15 of 23
..Identifiers
Naming rules
Must begin with a letter (a..z or A..Z) or an
underscore ( _ )
Can contain letters, digits or underscore
Can be up to 127 characters
Page 16 of 23
..Identifiers
Valid identifiers
num
num1
number_one
_NumberOne
nUmBeRoNe_
Invalid identifiers
1num
Num1&2
number one
Number:One
nUmBeRoNe_$
Page 17 of 23
Constants
Page 18 of 23
..Constants
Unlike variable, the value assigned to a constant
cannot be changed
Advisable to write constants identifier in
UPPERCASE
Syntax
Example
const PI = 3.142;
Page 19 of 23
Data Types
Each variable has a data type
Data Type
ShortInt
Size
Whole number -128 to 127
Integer
LongInt
Real
Double
Boolean
True / False
Character
String
Holds text
Page 20 of 23
Variables
Page 21 of 23
..Variables
Page 22 of 23
Variable Declaration
Each variable must be declared before it can
be used
Syntax
Example
Page 23 of 23
..Variable Declaration
Declare more than one variable of the same
data type
Syntax
Example
var
width,
height : real;
hour
: integer;
Summary
Basic Pascal program structure comprises
head, declaration and body sections
Important tokens in Pascal include
identifiers, constants, variables and reserved
words
Programmer must follow the syntax rules of
Pascal programming language
Page 25 of 23