Csi 07
Csi 07
Csi 07
PROGRAMMING
Subtitle
Content
7.1 Evolution
7.2 Translation
7.3 Programming paradigms
7.4 Common concepts
Objectives
Describe the evolution of programming languages from machine language to high-Level languages.
Understand how a program in a high-level language is translated into machine language using an interpreter or
a compiler.
Understand the procedural paradigm and the interaction between a program unit and data items in the
paradigm.
Understand the object-oriented paradigm and the interaction between a program unit and objects in this
paradigm.
To write a program for a computer, we must use a computer language. A computer language is a set of
predefined words that are combined into a program according to predefined rules (syntax). Over the
years, computer languages have evolved from machine language to high- level languages.
Programs today are normally written in one of the high-level languages. To run the program on a
computer, the program needs to be translated into the machine language of the computer on which it will
run.
The program in a high-level language is called the source program. The translated program in machine
language is called the object program.
Compilation : A compiler normally translates the whole source program into the object program.
Interpretation : Some computer languages use an interpreter to translate the source program into the
object program. Interpretation refers to the process of translating each line of the source program into the
corresponding line of the object program and executing the line.
2. Translation process
Compilation and interpretation differ in that the first translates the whole source code before
executing it, while the second translates and executes the source code a line at a time.
Semantic analyzer checks the sentences created by the syntax analyzer to be sure that they contain no ambiguity.
Code generator After unambiguous instructions are created by the semantic analyzer, each instruction is converted
to a set of machine language instructions for the computer on which the program will run.
3 - PROGRAMMING PARADIGMS
1. Introduction
Today computer languages are categorized according to the approach they use to
solve a problem. A paradigm, therefore, is a way in which a computer language
looks at the problem to be solved. We divide computer languages into four
paradigms: procedural, object-oriented, functional, and declarative
The object-oriented paradigm deals with active objects instead of passive objects.
We encounter many active objects in our daily life: a vehicle, an automatic door, a
dishwasher, and so on.
The actions to be performed on these objects are included in the object: the objects
need only to receive the appropriate stimulus from outside to perform one of the
actions.
One feature present in all procedural languages, as well as in other languages, is the
identifier—that is, the name of objects. Identifiers allow us to name objects in the
program.
A data type defines a set of values and a set of operations that can be applied to
those values. The set of values for each type is known as the domain for the type.
Most languages define two categories of data types: simple types (Primitive in Java)
and composite types (Non-Primitive in Java).
Variables are names for memory locations. Although the addresses are used by the
computer internally, it is very inconvenient for the programmer to use addresses.
A programmer can use a variable, such as count, to store the integer value of a
count number received in a test.
The use of literals is not considered good programming practice unless we are sure
that the value of the literal will not change with time (such as the value of π in
geometry).
However, most literals may change value with time. For example, if a sales tax is 8
per cent this year, it may not be the same next year.
Almost every program needs to read and/or write data. These operations can be
quite complex, especially when we read and write large files. Most programming
languages use a predefined function for input and output.
Input : Data is input by either a statement or a predefined function. Example in C
language