PPL Unit-1
PPL Unit-1
PPL Unit-1
ON
PRINCIPLES OF PROGRAMMING
LANGUAGES
PRINCIPLES OF PROGRAMMING LANGUAGES
B.Tech. IV Year I Sem. L T P C
Course Code: CS702PC 4 0 0 4
Course Objectives:
To introduce the various programming paradigms.
To understand the evolution of programming languages.
To understand the concepts of OO languages, functional languages, logical and
scripting languages.
To introduce the principles and techniques involved in design and implementation of
modern programming languages.
To introduce the notations to describe the syntax and semantics of programming
languages.
To introduce the concepts of concurrency control and exception handling.
To introduce the concepts of ADT and OOP for software development.
Course Outcomes:
Ability to express syntax and semantics in formal notation.
Ability to apply suitable programming paradigm for the application.
Ability to compare the features of various programming languages.
Able to understand the programming paradigms of modern programming languages.
Able to understand the concepts of ADT and OOP.
Ability to program in different language paradigms and evaluate their relative
benefits.
UNIT-I
Preliminary Concepts: Reasons for studying concepts of programming languages,
programming domains, language evaluation criteria, influences on language design, language
categories, language design trade-offs, implementation methods, programming environments,
Evolution of Major Programming Languages.
Syntax and Semantics: General problem of describing syntax, formal methods of describing
syntax, attribute grammars, describing the meanings of programs
UNIT-II
Names, Bindings, and Scopes: Introduction, names, variables, concept of binding, scope,
scope and lifetime, referencing environments, named constants
Data types: Introduction, primitive, character, string types, user defined ordinal types, array,
associative arrays, record, tuple types, list types, union types, pointer and reference types,
type checking, strong typing, type equivalence
Expressions and Statements: Arithmetic expressions, overloaded operators, type
conversions, relational and boolean expressions, short- circuit evaluation, assignment
statements, mixed-mode assignment
Control Structures – introduction, selection statements, iterative statements, unconditional
branching, guarded commands.
R16 B.TECH CSE.
UNIT-III
Subprograms: Fundamentals of subprograms, design issues for subprograms, local
referencing environments, parameter passing methods, parameters that are subprograms,
calling subprograms indirectly, overloaded subprograms, generic subprograms, design issues
for functions, user defined overloaded operators, closures, co routines
Implementing subprograms: General semantics of calls and returns, implementing simple
subprograms, implementing subprograms with stack-dynamic local variables, nested
subprograms, blocks, implementing dynamic scoping
Abstract Data types: The concept of abstraction, introductions to data abstraction, design
issues, language examples, parameterized ADT, encapsulation constructs, naming
encapsulations
UNIT-IV
Object Oriented Programming: Design issues for OOP, OOP in Smalltalk, C++, Java, Ada
95, Ruby, Implementation of Object-Oriented constructs.
Concurrency: introduction, introduction to subprogram level concurrency, semaphores,
monitors, message passing, Ada support for concurrency, Java threads, concurrency in
functional languages, statement level concurrency.
Exception Handling and Event Handling: Introduction, exception handling in Ada, C++,
Java, introduction to event handling, event handling with Java and C#.
UNIT-V
Functional Programming Languages: Introduction, mathematical functions, fundamentals
of functional programming language, LISP, support for functional programming in primarily
imperative languages, comparison of functional and imperative languages
Logic Programming Language: Introduction, an overview of logic programming, basic
elements of prolog, deficiencies of prolog, applications of logic programming.
Scripting Language: Pragmatics, Key Concepts, Case Study: Python – Values and Types,
Variables, Storage and Control, Bindings and Scope, Procedural Abstraction, Data
Abstraction, Separate Compilation, Module Library. (Text Book 2)
TEXT BOOKS:
1. Concepts of Programming Languages, Robert .W. Sebesta 10th edition, Pearson
Education.
2. Programming Language Design Concepts, D. A. Watt, Wiley India Edition.
REFERENCE BOOK:
1. Programming Languages, A.B. Tucker, R.E. Noonan, TMH.
2. Programming Languages, K. C. Louden and K A Lambert., 3rd edition, Cengage
Learning.
3. Programming Language Concepts, C Ghezzi and M Jazayeri, Wiley India.
4. Programming Languages 2nd Edition Ravi Sethi Pearson.
5. Introduction to Programming Languages Arvind Kumar Bansal CRC Press.
CONTENTS
UNIT-I
1. Reasons for studying
2. Concepts of programming languages
3. Programming domains
6. Language categories
9. Programming environments.
UNIT-II
1. Introduction
2. primitive
3. character
4. user defined, array
5. Associative, record, union, pointer and reference types, design and implementation uses
related to these types.
6. Names, Variable, concept of binding, type checking.
7. Strong typing
8. Type compatibility
9. Named constants
10. Variable initialization
UNIT-III
1. Fundamentals of sub-programs
2. Scope and lifetime of variable
3. Static and dynamic scope
4. Design issues of subprograms and operations, local referencing environments
5. Parameter passing methods
6. Overloaded sub-programs
7. Generic sub-programs
8. Parameters that are sub-program names
9. Design issues for functions user defined overloaded operators, co routines.
UNIT-IV
1. Abstract Data types
2. Concurrency
3. Exception handling
4. Logic Programming Language
UNIT-V
1. Functional Programming Languages
2. Introduction
3. LISP, ML, Haskell
4. Scripting Language: Pragmatics
5. Python
6. Procedural abstraction, data abstraction, separate compilation, module library
UNIT - I
PRELIMINARY CONCEPTS
• This in turn leads to the ability to use a language more intelligently, as it was designed to
be used.
• Ability to design new languages
• The more languages you gain knowledge of, the better understanding of programming
languages concepts you understand.
• Overall advancement of computing
• In some cases, a language became widely used, at least in part, b/c those in positions to
choose languages were not sufficiently familiar with P/L concepts.
• 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.
• Do you think IBM has something to do with it?
Programming Domains
• 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.
• Business applications
– The first successful language for business was COBOL.
– Produce reports, use decimal arithmetic numbers and characters.
– The arrival of PCs started new ways for businesses to use computers.
– Spreadsheets and database systems were developed for business.
• Artificial intelligence
– Symbolic rather than numeric computations are manipulated.
– Symbolic computation is more suitably done with linked lists than arrays.
– LISP was the first widely used AI programming language.
• Systems programming
– The O/S and all of the programming supports tools are collectively known as its system
software.
– Need efficiency because of continuous use.
• Scripting languages
– Put a list of commands, called a script, in a file to be executed.
– 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.
• Special-purpose languages
Language Evaluation Criteria
Readability
• 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”
– 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.
– Meaning is context independent. Pointers should be able to point to any type of variable
or data structure. The lack of orthogonality leads to exceptions to the rules of the
language.
– A relatively small set of primitive constructs can be combined in a relatively small
number of ways to build the control and data structures of the language.
– Every possible combination is legal and meaningful.
– Ex: page 11 in book.
– The more orthogonal the design of a language, the fewer exceptions the language rules
require.
– The most orthogonal programming language is ALGOL 68. Every language construct
has a type, and there are no restrictions on those types.
– This form of orthogonality leads to unnecessary complexity.
• Control Statements
– It became widely recognized that indiscriminate use of goto statements severely reduced
program readability.
–{
sum += incr;
incr++;
loop1:
loop2:
sum += incr;
go to loop2;
next:
incr++;
go to loop1:
out:
– 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.
Syntax Considerations
– The syntax of the elements of a language has a significant effect on readability.
– The following are examples of syntactic design choices that affect readability:
• Identifier forms: Restricting identifiers to very short lengths detracts from
readability. ANSI BASIC (1978) an identifier could consist only of a single letter
of a single letter followed by a single digit.
• Special Words: Program appearance and thus program readability are strongly
influenced by the forms of a language’s special words. Ex: while, class, for. C
uses braces for pairing control structures. It is difficult to determine which group
is being ended. Fortran 95 allows programmers to use special names as legal
variable names.
• Form and Meaning: Designing statements so that their appearance at least
partially indicates their purpose is an obvious aid to readability.
• Semantic should follow directly from syntax, or form.
• Ex: In C the use of static depends on the context of its appearance.
If used as a variable inside a function, it means the variable is created at compile
time.
If used on the definition of a variable that is outside all functions, it means the
variable is visible only in the file in which its definition appears.
Writability
It is a 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 the 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.
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
– Categories
– 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)
Evaluation Criteria: Others
– Portability: The ease with which programs can be moved from one implementation to
another
• Generality
– The applicability to a wide range of applications
• Well-definedness
– The completeness and precision of the language‘s official definition
–
Language Categories:
• Imperative
– Central features are variables, assignment statements, and iteration
– C, Pascal
• Functional
– Main means of making computations is by applying functions to given parameters
– LISP, Scheme
• Logic
– Rule-based
– Rules are specified in no special order
– Prolog
• Object-oriented
– Encapsulate data objects with processing
– Inheritance and dynamic type binding
– Grew out of imperative languages
– C++, Java
Language Design Trade-Offs
Programming Environments
• The collection of tools used in software development
• UNIX
– An older operating system and tool collection
• Borland JBuilder
– An integrated development environment for Java
• Microsoft Visual Studio.NET
– A large, complex visual environment
– Used to program in C#, Visual BASIC.NET, Jscript, J#, or C++
Implementation Methods
• Compilation
– Programs are translated into machine language
• Pure Interpretation
– Programs are interpreted by another program known as an interpreter
• Hybrid Implementation Systems
– A compromise between compilers and pure interpreters
The operating system and language implementation are layered over Machine interface of a computer
Compilation
• Translate high-level program (source language) into machine code (machine language)
• Slow translation, fast execution
• Compilation process has several phases:
– lexical analysis: converts characters in the source program into lexical units
– syntax analysis: transforms lexical units into parse trees which represent the syntactic
structure of program
– Semantics analysis: generate intermediate code
– code generation: machine code is generated
• Load module (executable image): the user and system code together
• Linking and loading: the process of collecting system program and linking them to user program
• Connection speed between a computer‘s memory and its processor determines the speed of a
computer
• Program instructions often can be executed a lot faster than the above connection speed; the
connection speed thus results in a bottleneck
• Known as von Neumann bottleneck; it is the primary limiting factor in the speed of computers
Pure Interpretation
• No translation
• Easier implementation of programs (run-time errors can easily and immediately displayed)
• Slower execution (10 to 100 times slower than compiled programs)
• Often requires more space
• Becoming rare on high-level languages
Significant comeback with some Web scripting languages (e.g., JavaScript)
Hybrid Implementation Systems
• A compromise between compilers and pure interpreters
• A high-level language program is translated to an intermediate language that allows easy
interpretation
• Faster than pure interpretation
• Examples
– Perl programs are partially compiled to detect errors before interpretation
– Initial implementations of Java were hybrid; the intermediate form, byte code, provides
portability to any machine that has a byte code interpreter and a run- time system (together, these are
called Java Virtual Machine)
Just-in-Time Implementation Systems
• Initially translate programs to an intermediate language
• Then compile intermediate language into machine code
• Machine code version is kept for subsequent calls
• JIT systems are widely used for Java programs
• .NET languages are implemented with a JIT system
Preprocessors
• Preprocessor macros (instructions) are commonly used to specify that code from another file is to be
included
• A preprocessor processes a program immediately before the program is compiled to expand
embedded preprocessor macros
• A well-known example: C preprocessor
– expands #include, #define, and similar macros
\
EVOLUTION OF MAJOR PROGRAMMING LANGUAGES: