Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of...

34
Principles of Programming Languages RCS-503

Transcript of Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of...

Page 1: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Principles of Programming

Languages

RCS-503

Page 2: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

UNIT-I

Introduction

Dr. Mohit Mittal

Page 3: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Contents

Brief Introduction to Programing Languages

History

Language Development

Software Architecture

Requirements of Good Language

Design Issues

Language Paradigms

Language Translation Issues

Page 4: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Definition A programming language is a set of commands, instructions, and

other syntax use to create a software program. Languages that

programmers use to write code are called "high-level languages." This

code can be compiled into a "low-level language," which is recognized

directly by the computer hardware.

A programming language is a formal language which comprises a set

of instructions used to produce various kinds of output. Programming

languages are used to create programs that implement

specific algorithms.

Page 5: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Why study programming languages

To improve your ability to develop effective algorithms

To improve your use of existing programming languages

To increase your vocabulary of useful programming constructs

To allow a better choice of programming language

To make it easier to learn a new language

To make it easier to design a new language

Page 6: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Brief History

1951- 55: Experimental use of expression compilers.

1956- 60: FORTRAN, COBOL, LISP, Algol 60.

1961- 65: APL notation, Algol 60 (revised), SNOBOL, CPL.

1966- 70: APL, SNOBOL 4, FORTRAN 66, BASIC, SIMULA,

Algol 68, Algol-W, BCPL.

1971- 75: Pascal, PL/1 (Standard), C, Scheme, Prolog.

1976- 80: Smalltalk, Ada, FORTRAN 77, ML.

Page 7: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Brief History (Cont..)

1981- 85: Smalltalk-80, Prolog, Ada 83.

1986- 90: C++, SML, Haskell.

1991- 95: Ada 95, TCL, Perl.

1996- 2000: Java.

2000- 05: C#, Python, Ruby, Scala.

Page 8: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Language Development

Numerically based languages: Computing mathematical

expressions.

FORTRAN, Algol, Pascal, PL/1, BASIC, C, C++.

Business languages: English-like notation

COBOL (Common Business Oriented Language)

Artificial intelligence languages: Tree search; Rule-based

paradigm

LISP (LISt Processing), PROLOG (PROgramming in LOGic)

Page 9: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Language Development

System languages

C, C++ Script languages: AWK, Perl, TCL/TK

Web programming

HTML, XML, Java, Microsoft *.NET family

Page 10: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Software Architectures

Mainframe era

Batch Processing (batches of files)

Interactive Processing (time sharing)

Effects on language design

▪ File I/O in batch processing

▪ Error handling in batch processing

▪ Time constraints in interactive processing

Page 11: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Software Architectures (Cont…)

Personal Computers

Interactive Processing

Embedded system environments

Effects on language design

▪ No need for time sharing

▪ Good interactive graphics

▪ Non-standard I/O devices for embedded systems

Page 12: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Software Architectures (Cont…)

Network era

Client-server model of computing

▪ Server: a program that provides information

▪ Client - a program that requests information

Effects on language design

▪ Interaction between the client and server programs Active web

pages, Security issues, Performance

Page 13: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Requirements of Good Language

Conceptual integrity

Orthogonality

Naturalness for the application

Support for abstraction

Ease of program verification

Programming environment

Portability of programs

Page 14: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Requirements of Good Language

Cost of use

Cost of execution

Cost of program translation

Cost of program creation, testing, and use

Cost of program maintenance

Page 15: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Language Design Issues

Design to

Run efficiently : early languages

Easy to write correctly : new languages

▪ Data typing features in ML

▪ Class of C++

▪ Package of Ada

Page 16: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Computer Architecture

Well-known computer architecture: Von Neumann

Imperative languages, most dominant, because of von Neumann

computers

– Data and programs stored in memory

– Memory is separate from CPU

– Instructions and data are piped from memory to CPU

– Basis for imperative languages

• Variables model memory cells

• Assignment statements model piping

• Iteration is efficient

Page 17: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Virtual Computers

Hardware realization

Physical devices

Firmware realization

microprogramming

Software simulation

Some other programming language

Combination of these techniques

Page 18: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Major Components of Computer Data: Various kinds of elementary and structured data.

Primitive operations

Sequence control : Controlling the sequence of primitive operations

execution.

Data access : Controlling the data supplied to each execution of an

operation.

Storage management : Controlling the allocation of storage for

programs and data.

Operating environment : Providing mechanisms for communication

with an external environment containing programs and data.

Page 19: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Data & OperationsMain memory

High-speed register

High-speed cache memory

External files

A set of build-in primitive operations

Arithmetic operations on each built-in numeric data (+,-,*,/)

Testing various properties of data items (test for zero, positive, and

negative numbers)

Accessing and modifying various parts of a data item

Controlling input-output devices

Sequence control (jumps)

Page 20: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Sequence ControlThere is an interpreter :

Fetch the instruction

Decode instruction

Fetch designated operands

Branch to designated operation

Execute primitive operations 1 to n

Page 21: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Storage Management Keeping all resources of the computer operating as much as possible

Memory

Central processor

External data devices

Multiprogramming

Cache memory

Page 22: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Language Paradigms

Imperative / procedural languages

Applicative / functional languages

Rule-based / declarative languages

Object-oriented languages

Page 23: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Imperative / procedural languages

Statement oriented languages that change machine state

(C, Pascal, FORTRAN, COBOL)

Computation: a sequence of machine states (contents of memory)

Syntax: S1, S2, S3, ... where S1, S2, … are statements

Page 24: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Applicative / functional languages

Programming consists of building the function that computes the

answer

Computation: Function composition is major operation (ML, LISP)

Syntax: P1(P2(P3(X)))

Page 25: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Rule-based / declarative languages

Computation: Actions are specified by rules that check for the

presence of certain enabling conditions. (Prolog)

The order of execution is determined by the enabling conditions, not

by the order of the statements.

Syntax: Condition Action

Page 26: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Object-oriented languages

Imperative languages that merge applicative design with imperative

statements (Java, C++, Smalltalk)

Syntax: Set of objects (classes) containing data (imperative

concepts) and methods (applicative concepts)

Page 27: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Language Translation Issues

Programming language Syntax

▪ Key criteria concerning syntax

▪ Basic syntactic concepts

▪ Overall Program-Subprogram structure

Stages in Translation

▪ Analysis of the source program

▪ Synthesis of the object program

▪ Bootstrapping

Page 28: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Syntax & Key Criteria

The syntax of a programming language describes the structure of

programs without any consideration of their meaning.

Readability – a program is considered readable if the algorithm and

data are apparent by inspection.

Write-ability – ease of writing the program.

Verifiability – ability to prove program correctness (very difficult

issue)

Translatability – ease of translating the program into executable

form.

Lack of ambiguity – the syntax should provide for ease of avoiding

ambiguous structures

Page 29: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Syntactic Concepts

Character set – The alphabet of the language. Several different

character sets are used: ASCII, EBCIDIC, Unicode

Identifiers – strings of letters of digits usually beginning with a letter

Operator Symbols – +-*/

Keywords or Reserved Words – used as a fixed part of the syntax of

a statement

Page 30: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Syntactic Concepts(Cont..)

Noise words – optional words inserted into statements to improve

readability

Comments – used to improve readability and for documentation

purposes. Comments are usually enclosed by special markers

Blanks – rules vary from language to language. Usually only

significant in literal strings

Delimiters – used to denote the beginning and the end of syntactic

constructs

Expressions – functions that access data objects in a program and

return a value

Statements – these are the sentences of the language, they describe a

task to be performed

Page 31: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Program-subprogram structure

Separate subprogram definitions: Separate compilation, linked at

load time E.g. C/C++

Separate data definitions: General approach in OOP.

Nested subprogram definitions: Subprogram definitions appear as

declarations within the main program or other subprograms. E.g.

Pascal

Separate interface definitions: C/C++ header files

Data descriptions separated from executable statements. A

centralized data division contains all data declarations. E.g. COBOL

Un-separated subprogram definitions: No syntactic distinction

between main program statements and subprogram statements. E.g.

BASIC

Page 32: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Stages in Translation

Page 33: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Lexical Analysis: The first phase of scanner works as a text scanner. This phase scans the

source code as a stream of characters and converts it into meaningful lexemes. Lexical

analyzer represents these lexemes in the form of tokens as:

<token-name, attribute-value>

Syntax Analysis: The next phase is called the syntax analysis or parsing. It takes the token

produced by lexical analysis as input and generates a parse tree (or syntax tree).

Semantic Analysis: Semantic analysis checks whether the parse tree constructed follows

the rules of language

Intermediate Code Generation: After semantic analysis the compiler generates an

intermediate code of the source code for the target machine. It represents a program for

some abstract machine. It is in between the high-level language and the machine language

Stages in Translation

Page 34: Principles of Programming Languages · 2019-08-20 · Definition A programming language is a set of commands, instructions, and other syntax use to create a software program. Languages

Code Optimization: Optimization can be assumed as something that removes unnecessary

code lines, and arranges the sequence of statements in order to speed up the program

execution without wasting resources (CPU, memory).

Code Generation : the code generator takes the optimized representation of the

intermediate code and maps it to the target machine language. performs the task as the

intermediate code would do.

Symbol Table: It is a data-structure maintained throughout all the phases of a compiler. All

the identifier's names along with their types are stored here.

Stages in Translation