Unit 1 PPL
Unit 1 PPL
Unit 1 PPL
Will it draw?
Importance of Studying Programming Languages
Output
CPU Devices
Input
Devices
Main Secondary
Memory Memory
Functional View of a Computer
▪ Humans interact with computers via Input and
E.g., Keyboard Output (IO) devices
and mouse E.g., Monitor
The program to iterate through each element in the array, compare the
item value with 5, and if the item is bigger than 5, push it into an array.
Programming Paradigms- IMPERATIVE and DECLARATIVE
use mnemonics to represent machine instructions
● Imperative programming: telling the "machine”
ØEach statement
(computer) how toin
do assembly language
something, and as a result corresponds to one statement in
machine language.
what you want to happen will happen.
ØEach statement
Imperative in assembly language
style of programming: corresponds
Declarative to one statement in
style of programming:
machine
var numberslanguage.
= [1,2,3,4,5] var numbers = [1,2,3,4,5]
var doubled = []
ØAssembly language programs var have the same advantages
doubled = numbers.map(function(n) and
disadvantages as machine
for(var i = 0; i < numbers.length; i++) language
{ { programs.
var newNumber = numbers[i] * 2 return n * 2
Compare the following machine
doubled.push(newNumber) language
}) and assembly language programs:
}
console.write(doubled) //=> [2,4,6,8,10] console.log(doubled) //=> [2,4,6,8,10]
Applicative Languages
● Programming language is to look at the function that the program represents
rather than just the state changes as the program executes, statement by
statement.
● Focus on the desired result rather than at the available data.
● What is the function that must be applied to the initial machine state by
accessing the initial set of variables and combining them in specific ways to
get an answer?
● The languages which emphasize this view are called applicative or functional
languages.
Applicative Languages
● LISP and ML are two functional languages
Rule based Languages
● Execute by checking for the presence of a certain enabling condition and,
when present, executing an appropriate action.
● The most common rule-based language is Prolog, also called a logic
programming
Rule based Languages
Object Oriented Languages
● Complex data objects are built, then a limited set of functions are designed
to operate on those data.
● Complex objects are designed as extensions of simpler objects, inheriting
properties of the simpler object.
● The best of two of the other computational models.
○ By building concrete data objects, an object-oriented program gains
the efficiency of imperative languages.
○ By building classes of functions that use a restricted set of data
objects, we build the flexibility and reliability of the applicative model.
Generality of Computational Model
Programming Paradigms- PROCEDURAL/STRUCTURED
● mnemonics
use Procedural programming is a computer
to represent programming
machine language that organises our code into small
instructions
programs" that use and change our datas.
ØEach statement
● Structured programmingin assembly language
is a programming paradigm corresponds to one statement
recommending hierarchical division intoin
machine
blockslanguage.
of code with one entry point and one or more exit points.
● In structured programming we use three main structures :
ØAssembly
○ sequences language
(instruction _1; programs have
instruction _2;…; the
instruction _n same advantages and
disadvantages
○ choices (if, asif...else,
machine switch,language
case) programs.
○ iterations (while, repeat, for).
Compare the variables,
● Key words: following machine
types, language
procedures anddatas.
and abstract assembly language
Using: network programs:
systems, operating
systems, etc.
● Procedural/structured languages:
Fortran , Cobol , Pascal, c, ,c++ etc,
Programming Paradigms- PROCEDURAL/STRUCTURED
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms-Object-oriented programming
● Object-oriented programming is a programming paradigm in which programs are defined using
objects - the state of the connecting elements (or fields) and behavior (or method).
use
● mnemonics to represent
Object-oriented computer programmachine
is expressedinstructions
as a set of such objects, which communicate with
each other in order to perform tasks.
ØEach statement in assembly language corresponds to one statement in
● Key words: classes and objects, inheritance, encapsulation, polymorphism.
machine
● Using:language.
www and stand-alone applications.
● Object-oriented
ØAssembly languages
language programs have the same advantages and
○ Simula,
disadvantages
○ Smalltalk,as machine language programs.
○ C++,
Compare the following machine language and assembly language programs:
○ C#,
○ Java, others.
Programming Paradigms- Object Oriented
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms- Functional Programming
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms- Functional Programming
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms-Logical programming
● The paradigm of logic programming is a programming method in which the program is given as a
set of relations, and the relationship between these dependencies.
● Key words: facts, reports, queries.
● Using: theoretical, artificial intelligence.
● Logical languages:
use mnemonics
○ Gödel, to represent machine instructions
○ Fril,
ØEach statement in assembly language corresponds to one statement in
○ Prolog, others.
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms- Logical programming
Smalltalk
SQL
PhP
Programming Environment
Impact of
Machine
Architectures
Impact of Machine Architectures - THE OPERATION OF A COMPUTER
Computer Hardware
● A computer is an integrated set of algorithms and data structures capable of storing
and executing programs.
● A computer may be constructed as an actual physical device using wires, integrated
circuits, circuit boards, and the like, in which case it is termed an actual computer or
hardware computer.
● it may also be constructed via software by programs running on another computer,
in which case it is a software-simulated computer.
● A programming language is implemented by construction of a translator, which
translates programs in the language into machine language programs that can be
directly executed by some computer.
Impact of Machine Architectures - THE OPERATION OF A COMPUTER
Computer Hardware
1. Data. A computer must provide various kinds of elementary data items and data structures to be
manipulated.
2. Primitive operations. A computer must provide a set of primitive operations useful for
manipulating the data.
3. Sequence control. A computer must provide mechanisms for controlling the sequence in which
the primitive operations are to be executed.
4. Data access. A computer must provide mechanisms for controlling the data supplied to each
execution of an operation.
5. Storage management. A computer must provide mechanisms to control the allocation of storage
for programs and data
6. Operating environment. A computer must provide mechanisms for communication with an
external environment containing programs and data to be processed.
Impact of Machine Architectures - THE OPERATION OF A COMPUTER
Firmware of Computers
● Common alternative to the strict hardware realization of a computer is the
firmware computer simulated by a microprogram running on a special micro
programmable hardware computer.
● Microprogram simulation of a computer is sometimes termed emulation.
● We also refer to the resulting computer as a virtual computer because it is
simulated by the microprogram; without this microprogrammed simulation, the
machine would not exist.
Impact of Machine Architectures - THE OPERATION OF A COMPUTER
Translators and Virtual Architectures
● An attribute may be
○ static: can be determined at translation (compilation) time, or
○ dynamic: can be determined only at execution time.
Impact of Machine Architectures - VIRTUAL COMPUTERS AND BINDING TIMES
Binding and Binding Time -Importance of Binding Times
Link
Impact of Machine Architectures - VIRTUAL COMPUTERS AND BINDING TIMES
Binding Time -Importance of Binding Times
● Language design time: built-in features such as keywords
● Language implementation time: implementation dependent semantics such as bit-width of an
integer
● Program writing time: names chosen by programmer
● Compile time: bindings of high-level constructs to machine code
● Link time: final bindings of names to addresses
● Load time: Physical addresses (can change during run time)
● Run time: bindings of variables to values, includes many bindings which change during execution
Impact of Machine Architectures - VIRTUAL COMPUTERS AND BINDING TIMES
Binding and Binding Time -Classes of Binding Times
1. Execution time (run time)
a. On entry to a subprogram or block.
b. At arbitrary points during execution.
2. At arbitrary points during execution.
a. Bindings chosen by the programmer.
b. Bindings chosen by the translator.
3. Language implementation time.
4. Language definition time.
Impact of Machine Architectures - VIRTUAL COMPUTERS AND BINDING TIMES
Binding and Binding Time -Classes of Binding Times
● consider the simple assignment statement X=X+10
● Points to Think:
○ Set of types for Variable X.
○ Type of variable X.
○ Set of possible values for variable X.
○ Value of Variable X.
○ Representation of the constant 10.
○ Properties of the operator +.
Programming Languages
Machine languages and assembly languages are also called low-level languages
1. Machine languages.
2. Assembly languages.
3. High-level languages.
Programming Languages
Machine languages and assembly languages are also called low-level languages
● A Machine language program consists of a sequence of zeros and ones.
● Each kind of CPU has its own machine language.
● Advantages
○ Fast and efficient
○ Machine oriented
○ No translation required
● DisadvantageS
○ Not portable
○ Not programmer friendly
Assembly language programs
use
● mnemonics toinrepresent
Each statement machine
assembly language instructions
corresponds to one statement in machine language.
ØEach statement
● Assembly in programs
language assemblyhavelanguage corresponds
the same advantages to one statement
and disadvantages as machinein
language
machine programs.
language.
● Compare the following machine language and assembly language programs:
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
High-Level Programming Languages
● A high-level language (HLL) has two primary components
use mnemonics to represent machine instructions
○ a set of built-in language primitives and grammatical rules
ØEach statement in assembly language corresponds to one statement in
○ a translator
● A HLL
machine language program consists of English-like statements that are governed by a strict
language.
syntax.
ØAssembly
● Advantages language programs have the same advantages and
disadvantages as machine
○ Portable or machinelanguage
independentprograms.
○ Programmer-friendly
Compare the following machine language and assembly language programs:
● Disadvantages
○ Not as efficient as low-level languages
○ Need to be translated
○ Examples : C, C++, Java, FORTRAN, Visual Basic, and Delphi.
Programming Paradigms-Functional programming
● Functional programming is a programming paradigm in which the functions are the core values
and the emphasis is on valuation (often recursive) function, and not to execute commands.
● Theoretical basis for functional programming was developed in the 19330s of the Twentieth century
by Alonzo Church's
use mnemonics lambda calculus,
to represent called lambda
machine calculus with types.
instructions
● Key words: functions, lambda calculus, parametric polymorphism.
ØEach
● Using:statement
theoretical, in in assembly language
telecommunications, corresponds to one statement in
in financial calculations.
● Functional
machine languages:
language.
○ Lisp,
ØAssembly
○ ML, language programs have the same advantages and
○ Haskell, as machine language programs.
disadvantages
○ H#,
Compare
○ Erlangthe following machine language and assembly language programs:
○ others.