Module 1. Programming Methodologies
Module 1. Programming Methodologies
CST-207
Introduction
Introduction
Programming Paradigms
Abstraction in Languages
Sequence Control
Subprogram Control
Data Control
Storage Management
2
Books
Main:
1. Pratt: Programming language design and implementation, PHI.
2. Sebasta: Concept of programming language, Addison Wesley.
Reference:
1. Ghezzi and Jazayeri: Programming Language Concepts, John Wiley
& Sons.
2. Sethi Ravi: Programming Language Concepts & Constructs, Addison
Wesley
3. Louden: Programming Languages Priciples and Practice, Cengage
Learning.
4. Friedman and Wand: Essential of Programming Languages, PHI.
3
Weight Distribution
sites.google.com/a/mnit.ac.in/arka/home/cst-207
5
Course Objective
To learn about
Programming Methodologies and Principles
Different programming paradigms
To understand concepts of syntax, translation,
abstraction, and implementation
Problem solving
6
Course Outcomes
Outcomes
Ability to understand structures of languages
Ability to solve simple algorithmic problems
Ability to write efficient and effective codes
7
Language Principles
Syntax
What constitutes a structurally correct
language
Names and Types
Vocabulary of a language variables,
functions etc.
Semantics
Meaning of a program
8
Programming Paradigms
9
Major Paradigms
10
Choice of Paradigm
Other considerations:
efficiency
compatibility with existing code
availability of translators
11
Von Neumann Architecture
12
A more complex view
13
Memory Hierarchy
14
Layered View of Computer
15
Computer Components
Hardware
Firmware
Software
16
Hardware-level operations
Fetch-execute cycle:
Processor fetches an instruction from
memory.
Processor executes the fetched instruction
17
Instruction Cycle
4.Write-
1.Fetch
back
3.Execute 2.Decode
18
Fetch-execute cycle
19
Firmware
20
Firmware Advantage
Flexibility
21
Software
Types:
Translation (Compilation)
Interpretation
22
Translation
24
Interpretation
Example:
Prolog interpreter written in C++
25
Interpretation
Advantages of interpretation:
Easy to be implemented
Easy to debug
Portability
Flexibility: easy to modify the interpreter
26
Virtual Machine
Program:
data + operations on these data
Computer:
implementation of data structures +
implementation of operations
Similarity?
Example: JVM
27
Interpreter / VM
28
Hardware, Firmware, and Software
computer
Hardware computer:
Elementary data items, very simple
operations
Firmware computer:
Elementary data items, machine language
instructions (we may have specialized
processors e.g. vector multiplication)
Software computer :
Each programming environment defines a
specific software computer.
29
TIOBE Index
Jul 2016 Jul 2015 Programming Language Ratings Change
P S -> T
L L
M M
L
31
Tombstone diagrams:
Combination rules
P P P
M S S -> T T
OK!
M M OK!
OK!
M OK!
P
P
L
WRONG! L S -> T
M
M
WRONG!
32
Compilation
Example: Compilation of C programs on an x86 machine
33
Cross compilation
Example: A C cross compiler from x86 to PPC
A cross compiler is a compiler which runs on one machine (the host machine) but
emits code for another machine (the target machine).
Host Target
x86 x86
35
Compiling a Compiler
Observation: A compiler is a program!
Therefore it can be provided as input to a language processor.
Example: compiling a compiler.
Java->x86 Java->x86
x86
36
Interpreters
Tetris Tetris
JVM JVM
JVM JVM
x86 PPC
x86 PPC
37
Bootstrapping
38
Bootstrap
Step 1a: build a compiler (v1) for Ada-S in another language.
v1
Ada-S ->M
v1 v1
Ada-S ->M Ada-S->M
C C->M M
M
This compiler can be used for
M bootstrapping on machine M but we do not
want to rely on it permanently!
39
Bootstrap
Step 2a: Implement v2 of Ada-S compiler in Ada-S
v2
Ada-S ->M
Q: Is it hard to rewrite the compiler in Ada-S?
Ada-S
v2 v2
Ada-S ->M v1 Ada-S->M
40
Bootstrap
Step 3a: Build a full Ada compiler in Ada-S
v3
Ada->M
Ada-S
Hand-written document on
1. P-code machine
42