You are on page 1of 62

• Branch: Computer Science and Engineering

• Course Title PRINCIPLES OF


PROGRAMMING LANGUAGES
• Course Objectives (CO) This course should
provide the students witha fairly good
concept of fundamental concepts and design
issues of programming languages and
become familiar with major programming
paradigms. Understand similarities and
differences between models and know when
to use them and also learn programming
techniques appropriate for each model.
SYLLABUS
• SECTION-A
• Introduction: Study of principles and major concepts in various programming
paradigms like imperative, functional, object-oriented and logic programming.
Introduction to various phases of compilers, Formal translation models: BNF
Grammars.
• Imperative Programming: Location, reference and expressions, assignment and
control, data types, blocks, procedures and modules.
• Object Oriented Programming: Classes and objects, abstraction and encapsulation,
inheritance, Polymorphism, virtual functions and classes, abstract classes.
• Logic Programming: Unification, SLD-resolution, Backtracking, Cuts. Concepts Of
Concurrent Programming: Processes, synchronization primitives.
• SECTION-B
• Functional Programming: Functions as first class objects, higher order functions,
polymorphic data types, type checking and type inference.
• Storage Management: Static storage management, Heap storage mgt
• Illustration of the above concepts using representative languages: C++, Java, and
Prolog etc.
Programming Languages: Design & Implementation
Prattt&amp ;Zelkowrtz,
Pearson Education 5th Edition
What is a Programming
Language?
• A programming language is a notational system
for describing computation in machine-readable
and human-readable form.
• Most of these forms are high-level languages,
which is the subject of the course.
• Assembly languages and other languages that are
designed to more closely resemble the computer’s
instruction set than anything that is human-
readable are low-level languages.
Why Study Programming Languages?

• In 1969, Sammet listed 120 programming


languages in common use – now there are many
more!
• Most programmers never use more than a few.
– Some limit their career’s to just one or two.
• The gain is in learning about their underlying
design concepts and how this affects their
implementation.
The Six Primary Reasons
• Increased ability to express ideas
• Improved background for choosing appropriate
languages
• Increased ability to learn new languages
• Better understanding of significance of
implementation
• Better use of languages that are already known
• Overall advancement of computing
Reason #1 - Increased ability to
express ideas
• The depth at which people can think is heavily influenced
by the expressive power of their language.
• It is difficult for people to conceptualize structures that
they cannot describe, verbally or in writing.
• Language in which they develop S/W places limits on the
kinds of control structures, data structures, and
abstractions they can use.
• Awareness of a wider variety of P/L features can reduce
such limitations in S/W development.
Expressing Ideas as Algorithms
• This includes a programmer’s to develop
effective algorithms
• Many languages provide features that can
waste computer time or lead programmers
to logic errors if used improperly
– E. g., recursion in Pascal, C, etc.
– E. g., GoTos in FORTRAN, etc.
Reason #2 - Improved background for
choosing appropriate languages
– Many programmers, when given a choice of
languages for a new project, continue to use the
language with which they are most familiar, even
if it is poorly suited to new projects.
– If these programmers were familiar with other
languages available, they would be in a better
position to make informed language choices.
Reason #3 - Increased ability to
learn new languages
• Programming languages are still in a state of
continuous evolution, which means continuous
learning is essential.
• Programmers who understand the concept of OO
programming will have easier time learning Java.
• Once a thorough understanding of the
fundamental concepts of languages is acquired, it
becomes easier to see how concepts are
incorporated into the design of the language being
learned.
Learning a New Language

• It is easier to learn a new language if you


understand the underlying structures of
language.
Examples:
– It is easier for a BASIC program to FORTRAN than
C.
– It is easier for a C++ programmer to learn Java.
– It is easier for a Scheme programmer to learn LISP.
Reason #4 - Better understanding of
significance of implementation
– Understanding of implementation issues leads
to an understanding of why languages are
designed the way they are.
– This in turn leads to the ability to use a
language more intelligently, as it was designed
to be used.
Reason #5 - Better use of languages
that are already known
• To allow a better choice of programming
language
• Some languages are better for some jobs
than others.
– FORTRAN and APL for calculations,
– COBOL and RPG (report program generator)
for report generation,
– LISP and PROLOG for AI, etc.
Reason #6 - Overall advancement
of computing
• Frequently, the most popular language may
not be the best language available.
• E.g., ALGOL 60 did NOT displace Fortran.
– Many believe that ALGOL 60 was a better
language than Fortran; however, Fortran was
most widely used. It is attributed to the fact
that the programmers and managers didn’t
understand the conceptual design of ALGOL
60.
• 4GL commonly used in database programming
and scripts examples include Perl, PHP, Python,
Ruby, and SQL. It is mainly used in data
processing and database handling applications
• 5GL designed to make computer “smarter”.
Examples: Mercury, OPS5, and Prolog, AI,
NLP.
• 4GL are designed to build specific programs,
sometimes called problem-oriented
languages/non-procedural languages (tells the
computer what to do, not how to do it),
and require less training than 3GLs.
• 5GL are designed to make the computer solve a
given problem without the programmer.
Programming Domains
• Scientific Applications
• Business Applications
• Artificial Intelligence
• Web Software
Numerically-Based Languages

• Many of the earliest computers were used


almost exclusively for scientific
calculations and consequently many of the
earliest attempts at languages were for
scientific purposes.
• Grace Murray Hopper’s A-0 and John
Backus’s Speedcoding ere designed to
compile simple arithmetic expressions.
Scientific applications
– In the early 40s computers were invented for
scientific applications.
– The applications require large number of
floating point computations.
– Fortran was the first language developed
scientific applications.
– ALGOL 60 was intended for the same use.
FORTRAN(formula translation)
• John Backus’s team at IBM developed FORTRAN
(for FORmula TRANslator) in 1955-1957.
• While FORTRAN was designed for numerical
computation, it included control structures,
conditions and input/output.
• FORTRAN’s popularity led to FORTRAN II in
1958, FORTRAN IV in 1962, leading to its
standardization in 1966, with revised standards
coming out in 1977 and 1990.
Business Languages
• Commercial data processing was one of the
earliest commercial applications of computers.
• Grace Murray Hopper et. al. at Univac developed
FLOWMATIC, an English-like language for
business applications.
• The U.S. Defense Dept. sponsored the effort to
develop COBOL (Common Business-Oriented
Language), which was standardized in 1960,
revised in 1961 & 1962, re-standarized in 1968,
1974, and 1984.
• Spreadsheets and database systems were
developed for business
Artificial Intelligence
• Artificial Intelligence deals with emulating
human-style reasoning on a computer.
• These applications usually involve symbolic
computation, where most of the symbols are
names and not numbers.
• Symbolic rather than numeric computations are
manipulated
• The most common data structure is the list, not the
matrix or array as in scientific computing and not
the record as in business computing
• Artificial intelligence requires more flexibility
than other programming domains.
Artificial Intelligence Languages
• The first AI language was IPL (International Processing
Language, developed by the Rand Corporation. Its low-
level design led to its limited use.
• John McCarthy of MIT developed LISP for the IBM 704
(which eventually led to Scheme and Common LISP).
LISP is a recursion-oriented, list-processing language that
facilitated game-playing programs.
• Yngve of MIT developed COMIT, a string-processing
language, which was followed by AT&T’s SNOBOL.
• Prolog was developed by Colmerauer, Roussel and
Kowalski based on predicate calculus and mathematical
logic.
Systems Languages

• Assembly languages were used for a very


long time operating systems programming
because of its power and efficiency.
• CPL, BCPL, C and C++ were later
developed for this purpose.
• Other languages for systems programming
included PL/I, BLISS, and extended
ALGOL.
Web Software
• Eclectic collection of languages:
– Markup (e.g., HTML) – used for annotating a
document in a manner that can be distinguished
from the text.
– Scripting (e.g., PHP) -PHP is a scripting
language used on Web server systems. Its code
is embedded in HTML documents. The code is
interpreted on the server before the document is
sent to a requesting browser.
– General-purpose (e.g., Java) – can be used for
a wide range of programming jobs.
Language Evaluation Criteria
• Readability – the ease with which
programs can be read and understood.
• Writability – the ease with which programs
can be developed for a given program
domain.
• Reliability – the extent to which a program
will perform according to its specifications.
What Do We Mean By Machine
Readability?
• A language is considered machine-readable if it
can be translated efficiently into a form that the
computer can execute.
• This requires that:
– A translation algorithm exists.
– The algorithm is not too complex.
• We can ensure machine readability by requiring
that programming languages be context-free
languages.
What Do We Mean By Human Readability?
• It is harder to define human readability in precise
terms.
• Generally this requires a programming language to
provide enough abstractions to make the
algorithms clear to someone who is not familiar
with the program’s details.
• As programs gets larger, making a language
readable requires that the amount of detail is
reduced, so that changes in one part of a program
have a limited effect on other parts of the program.
Language Evaluation Criteria

There are five characteristics of programming


languages that contribute to readability:
• Simplicity
• Orthogonality
• Control Statements
• Data types and Structures
• Syntax
Simplicity
• Software development was largely thought of in term of writing code
“LOC”.
• Language constructs were designed more from the point of view of the
computer than the users.
• Because ease of maintenance is determined in large part by the
readability of programs, readability became an important measure of
the quality of programs and programming languages. The result is a
crossover from focus on machine orientation to focus on human
orientation.
• The most important criterion “ease of use”
• Overall simplicity “Strongly affects readability”
– Too many features make the language difficult to learn. Programmers
tend to learn a subset of the language and ignore its other features.
“ALGOL 60” (hard to understand the conceptual design of ALGOL )
– Multiplicity of features is also a complicating characteristic “having
more than one way to accomplish a particular operation.”
– Ex “Java”:
• count = count + 1
• count += 1
• count ++
• ++count
– Although the last two statements have slightly different meaning from
each other and from the others, all four have the same meaning when
used as stand-alone expressions.
– Operator overloading where a single operator symbol has more than
one meaning.
– Although this is a useful feature, it can lead to reduced readability if
users are allowed to create their own overloading and do not do it
sensibly.
Orthogonality
– Makes the language easy to learn and read.
– The more orthogonal the design of a language, the fewer
exceptions the language rules require.
– A relatively small set of primitive constructs can be combined in a
relatively small number of ways – Every possible combination is
legal.
– In assembly language, there are different instructions for adding
memory to register or register to register (non-orthogonal)
– For a programming language to be orthogonal, language
constructs should not behave differently in different contexts.
Other non-orthogonality examples:
In Pascal functions can only return scalar values or
pointers.
In C/C++, arrays types cannot be returned from a
function
In C, local variables must be at the beginning of a block.
C passes ALL parameters by value except arrays (passed
by reference).
Control Statements
– In the 1950s and 1960s, the goto was the most common control
mechanism in a program; however, it could make programs less
readable.
– Basic and Fortran in the early 70s lacked the control statements
that allow strong restrictions on the use of gotos, so writing highly
readable programs in those languages was difficult.
– Since then, languages have included sufficient control structures.
– The control statement design of a language is now a less important
factor in readability than it was in the past.
• The introduction of while, for and if-then-else eliminate the need for
gotos and led to more readable programs.
Ex: Consider the following nested loops written in C
• while (incr < 20)
• {
• while (sum <= 100
• {
• sum += incr;
• }
• incr++;
• }

if C didn’t have a loop construct, this would be written as follows:


• loop1:
• if (incr >= 20) go to out;
• loop2:
• if (sum > 100) go to next;
• sum += incr;
• go to loop2;
• next:
• incr++;
• go to loop1:
• out:
Data Types and Structures
• A more diverse set of data types and the ability of
programmers to create their own increased
program readability:
– Booleans make programs more readable:
TimeOut = 1 vs. TimeOut = True
– The use of records to store complex data objects makes
programs more readable:
CHARACTER*30 NAME(100)
INTEGER AGE(100), EMPLOYEE_NUM(100)
REAL SALARY(100)
Wouldn’t it better if these were an array of records
instead of 4 parallel arrays?
Syntax
• Most syntactic features in a programming
language can enhance readability:
– Identifier forms – older languages (like
FORTRAN) restrict the length of identifiers,
which become less meaningful
– Special words – in addition to while, do and
for, some languages use special words to close
structures such as endif and endwhile.
– Form and meaning – In C a static variable
within a function and outside a function mean
two different things – this is undesirable.
Writability
• measure of how easily a language can be used to create programs for a chosen
problem domain.
• Most of the language characteristics that affect readability also affect writability.
• Simplicity and orthogonality
– A smaller number of primitive constructs and a consistent set of rules for
combining them is much better than simply having a large number of
primitives.
• Support for abstraction
– Abstraction means ability to define and then use complicated structures or
operations in ways that allow many of the details to be ignored.
– A process abstraction is the use of a subprogram to implement a sort algorithm
that is required several times in a program instead of replicating it in all places
where it is needed.
• Expressivity
– It means that a language has relatively convenient, rather than cumbersome,
ways of specifying computations.
– Ex: ++count ⇔ count = count + 1 // more convenient
and shorter
Reliability
• A program is said to be reliable if it performs to its specifications
under all conditions.
• Type checking: is simply testing for type errors in a given program,
either by the compiler or during program execution.
– The earlier errors are detected, the less expensive it is to make the
required repairs. Java requires type checking of nearly all
variables and expressions at compile time.
• Exception handling: the ability to intercept run-time errors, take
corrective measures, and then continue is a great aid to reliability.
• Aliasing: it is having two or more distinct referencing methods, or
names, for the same memory cell.
– It is now widely accepted that aliasing is a dangerous feature in a
language.
• Readability and writability: Both readability and writability
influence reliability.
Cost of Use
– Training programmers to use language
– Writing programs “Writability”
– Compiling programs
– Executing programs
– Language implementation system “Free compilers is the key,
success of Java”
– Reliability, does the software fail?
– Maintaining programs: Maintenance costs can be as high as two
to four times as much as development costs.
– Portability “standardization of the language”
– Generality (the applicability to a wide range of applications)
Influences on Language Design
Other factors have had a strong influence on
programming language design:
• Computer Architecture
• Programming Methodologies
Computer Architecture
• Most computers are still based on the von
Neumann architecture, which view memory as
holding both instructions and data interchangably.
• This has influenced the development of imperative
languages and has stifled the adaption of
functional languages.
• As parallel processing computers are developed,
there have been several attempts made to develop
languages that exploit their features.
Programming Methodologies
• New methods of program development
have led to advances in language design:
• These have included:
– structured programming languages
– data abstraction in object-oriented languages
Programming
Paradigm/Language Categories
• There are four different programming
language paradigms:
– Imperative
– Functional
– Declarative
– Object-Oriented
Imperative Languages
• Imperative languages are command-driven or statement-oriented languages.
Imperative program consists of commands for the computer to perform.
• Imperative programming focuses on describing how a program operates step by
step,
• It is also known as procedural languages (one or more procedures/subroutines)
• The basic concept is the machine state (the set of all values for all memory
locations).
• An imperative language uses a sequence of statements to determine how to
reach a certain goal. Means here you will get the answer how to do a task not
what to do.
• A program consists of a sequence of statements and the execution of each
statement changes the machine state.
• Programs take the form:
statement1;
statement2;
… …
• FORTRAN, COBOL, C, ALGOL, ADA, JAVA, Pascal, PL/I are all imperative
languages.
For example in C,
•int a = 4;
•int b = 5;
•int sum = 0;
•sum = a + b;
From assigning values to each variable to the
final addition of those values,each statement
changes the state of the program. Using a
sequence of five statements the program
shows how to add the numbers 4 and 5.
Functional Languages
• Also known as applicative languages.
• An functional programming language looks at the
function that the program represents rather than
the state changes as each statement is executed.
• The key question is: What function must be
applied to our initial machine and our data to
produce the final result?
• Statements take the form:
functionn(function1, function2, … (data)) … )
ML, Scheme, Python, and LISP are examples of
functional languages.
• Functional prog allows functions to be
treated as ordinary values because,
functions may freely operate on functions
as parameters and return new functions as
return values.
• It is a form of declarative programming. It
is considered one of the popular
programming paradigms that do
computation like mathematical functions
without changing state and mutating data.
There are two types:

•Pure Functional languages: It supports only


functional paradigm. Ex. Haskell.
•Impure Functional languages: It supports
both functional and imperative paradigm.
Ex. Lisp.
Logic Prog/Rule-Based Languages
• concentrate on what is the expected outcome for the
program instead of how the outcome is achieved.
• Logic program statements express facts and rules
about problems.
• Rule-based or declarative languages execute checking
to see if a particular condition is true and if so,
perform the appropriate actions.
• The enabling conditions are usually written in terms of
predicate calculus and take the form:
condition1  action1
condition2  action2
• Prolog is the best know example of a declarative
language.
Object-Oriented Languages
• In object-oriented languages, data structures and
algorithms support the abstraction of data and endeavor to
allow the programmer to use data in a fashion that closely
represents its real world use.
• Data abstraction is implemented by use of
– Encapsulation – data and procedures belonging to a
class can only be accessed by that classes (with
noteworthy exceptions).
– Polymorphism – the same functions and operators can
mean different things depending on the parameters or
operands,
– Inheritance – New classes may be defined in terms of
other, simpler classes.
5) Event-Driven programming languages:

These languages execute various operations based on user activities like


mouse click and other events.
For example: Visual Basic, Visual C++ and Java
6) Concurrent / parallel programming languages
concurrent programming is a technique in which two or more
processes start, run in an interleaved fashion through context
switching and complete in an overlapping time period.
These application programming interfaces support parallelism
in host languages.
Apache Beam.
Apache Flink.
Apache Hadoop.
Apache Spark.
CUDA.
7) Special purpose programming languages:
• These programming languages are used for special
task.
• Also called a "domain-specific language," a
special-purpose language designed to solve a finite
class of problems.
• example: LISP and Prolog were designed for AI.
• Tex was created for typesetting. SQL manipulates
databases. Mathematica is used for computations.
• COGO solves civil engineering problems,
Language Evaluation Criteria
• Readability – the ease with which
programs can be read and understood.
• Writability – the ease with which programs
can be developed for a given program
domain.
• Reliability – the extent to which a program
will perform according to its specifications.
What Do We Mean By Machine
Readability?
• A language is considered machine-readable if it
can be translated efficiently into a form that the
computer can execute.
• This requires that:
– A translation algorithm exists.
– The algorithm is not too complex.
• We can ensure machine readability by requiring
that programming languages be context-free
languages.
What Do We Mean By Human Readability?
• It is harder to define human readability in precise
terms.
• Generally this requires a programming language to
provide enough abstractions to make the
algorithms clear to someone who is not familiar
with the program’s details.
• As programs gets larger, making a language
readable requires that the amount of detail is
reduced, so that changes in one part of a program
have a limited effect on other parts of the program.

You might also like