PPL Unit-I
PPL Unit-I
PPL Unit-I
Languages
Unit-I
Prepared By:
Mrs.K.Pranathi
Asst.Professor(CSE)
GLWEC
Course objectives
• To briefly describe various programming paradigms.
• To provide conceptual understanding of High level design and
implementation.
• To introduce the power of scripting languages.
• To provide an introduction to formalisms for specifying syntax and
semantics of programming languages.
• To provide an exposure to core concepts and principles in
contemporary programming languages.
• To analyze and optimize the complexity of programming languages.
Outcomes
• Ability to express syntax and semantics in formal notation.
• Ability to apply suitable programming paradigm for the application.
• Gain knowledge and comparison of the features programming
languages.
• Identify and describe semantic issues associated with variable
binding ,scoping rules, parameter passing and exception handling.
• Understand the design issues of object-oriented and functional
languages.
Syllabus
Unit-I
PRELIMINARY CONCEPTS Reasons for Studying ,Concepts of Programming Languages,
Programming Domains ,Language Evaluation Criteria, Influences on Language Design, Language
Categories, Programming Paradigms-Imperative , Functional Programming , Logic programming.
Programming Language Implementation-compilation and Virtual Machines, Programming environments.
SYNTAX AND SEMANTICS The General Problems of Describing Syntax and semantics, formal
methods of describing syntax BNF, EBNF for common programming language features, parse trees,
Ambiguous Grammars, attribute grammars, denotational semantics and axiomatic semantics for common
programming language features.
Unit-II
Data types: Introduction, Primitive,Character, User-Defined,Array,Associative,Record,Union,Pointer and
Reference types, design and implementation uses related to these types. Names, Variables, Concept of
Binding, Type Checking, Strong typing, Type Compatibility ,Named Constants, variable initialization.
Expressions And Statements & Control Structures : Arithmetic, Relational and Boolean Expressions,
Short-Circuit Evaluation , Mixed-Mode Assignment, Assignment Statements, Control Structures-Statement
Level , Compound Statements Selection ,Iteration, Unconditional Statements, Guarded Commands.
Syllabus(contd..)
Unit-III
Sub Programs Block and Fundamentals of Sub-Programs: Scope and lifetime of variable
Static and dynamic scope, Design issues of subprogram and operations
Local Referencing Environments, Parameter passing methods.
Overloaded sub-programs, Generic sub programs, parameters that are sub program names,
Design issues for functions user defined overloaded operators, co-routines.
Unit-IV
Abstract types: Data Abstraction and encapsulation, Introductions to data abstraction, design
issues, Language examples, C++ Parameterized ADT, Object oriented programming in small talk.
C++,Java,C#,Ada95
Concurrency: Subprogram level Concurrency. Semaphores,Monitors, Message Passing . Java
threads, C# threads .Exception Handling: exceptions,exception propogation. Exception Handler in
Ada C++ and Java. Logical programming Language: Introduction and overview of logic
programming, Basic elements of prolog, application of logical programming.
Syllabus(contd..)
Unit-V
Functional Programming Languages: Introduction, fundamentals of FPL.LISP, ML, Haskell,
Introduction, Application of Functional Programming Languages, Comparison of functional and
imperative languages.
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 Books
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.
Programming Domains(continued..)
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.
Programming Domains(continued..)
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
• Overall simplicity
• Orthogonality-Control Statements, Data Types and
Structures,Syntax Considerations
• Writability-Support for abstraction, Expressivity
• Reliability-Type checking, Exception handling, Aliasing,
Readability and writability, Cost
Influences on Language Design
Computer architecture
• Von Neumann
• We use imperative languages, at least in part, because we use von
Neumann machines
• Data and programs stored in same memory
• Memory is separate from CPU
• Instructions and data are piped from memory to CPU
• Results of operations in the CPU must be moved back to memory
• Basis for imperative languages
– Variables model memory cells
– Assignment statements model piping
– Iteration is efficient
The Von Neumann Machine
Programming Methodologies
if age < 18
{
printf("You are not eligible to vote");
}
else
{
printf("You are eligible to vote");
}
Classification of High-level
Languages
• We can also classify high-level language several other categories based on the
programming paradigm.
• Structured programming (sometimes known as modular programming) is a
programming paradigm aimed at improving the clarity, quality, and development
time of a computer program by making extensive use of the structured control
flow constructs of selection (if/then/else) and repetition (while and for), block
structures, and subroutines.
• Hence, making it more efficient and easier to understand and modify.
• Structured programming frequently employs a top-down design model, in which
developers map out the overall program structure into separate subsections.
• Note, it is possible to do structured programming in any programming language.
Object Oriented Programming
• Any given procedure might be called at any point during a program's execution,
including by other procedures or itself.
• Object-oriented programming is a programming paradigm based on the concept
of "objects", which may contain data, in the form of fields, often known as
attributes; and code, in the form of procedures, often known as methods.
• A feature of objects is that an object's procedures can access and often modify
the data fields of the object with which they are associated.
• Thus, programmers define not only the data type of a data structure but also the
types of operations (functions) that can be applied to the data structure. In this
way, the data structure becomes an object that includes both data and functions.
In addition, programmers can create relationships between one object and
another.
Procedural Programming
• Procedural programming is a programming paradigm, derived
from structured programming, based upon the concept of the
procedure call. Procedures, also known as routines, subroutines, or
functions, simply contain a series of computational steps to be
carried out.
Advantages of High-Level
Languages
• High-level languages are programmer friendly. They are easy to
write, debug and maintain.
• They provide higher level of abstraction from machine languages.
• It is machine independent language.
• Easy to learn.
• Less error-prone, easy to find and debug errors.
• High-level programming results in better programming
productivity.
Disadvantages of High Level languages
• It takes additional translation time to translate the source code to
machine code.
• High-level programs are comparatively slower than low-level
programs.
• Compared to low-level programs, they are generally less memory
efficient.
• Cannot communicate directly with the hardware.
Programming Paradigms
• 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
Hybrid Implementation
Systems(Virtual Machines)
• 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
JavaVirtualMachine)
Just-in-Time Implementation Systems
<breakfast> ::= <drink> " and biscuit" <drink> ::= "tea" | "coffee"
Defining Grammar(continued…)
• The | operator indicates that the parts separated by it are choices. Which
means the non-terminal on the left can be any such part. Here the order
is unimportant, that is there is no difference between "tea" |
"coffee and "coffee" | "tea".
• Example 2: let's see how you express one or more digits in BNF:
<digits> ::= <digit> | <digit> <digits>
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
• Every string of symbols in the derivation is a sentential
form.
• A sentence is a sentential form that has only terminal
symbols .
• A leftmost derivation is one in which the leftmost
nonterminal in each sentential form is the one that is
expanded
• A derivation may be neither leftmost nor rightmost
• A parse tree is a hierarchical representation of a derivation
Parse Tree
Parse Tree(continued…)
Example:
Define a grammar for the letter language. A letter is a lower-case Latin letter
between a and z.
letter ::= "a" | "b" | "c" | "d" | ... | "z“
The | symbol indicates alternate choices for the rule’s definition. It’s actually
shorthand for multiple rules for the same nonterminal:
letter ::= "a" letter ::= "b" letter ::= "c" letter ::= "d" ... letter ::= "z“.
Extended BNF
• Optional parts are placed in brackets ([]) <proc_call> -> ident
[ ( <expr_list>)]
• Put alternative parts of RHSs in parentheses and separate them
with vertical bars
• <term> -> <term> (+ | -) const
• Put repetitions (0 or more) in braces ({})<ident> -> letter {letter
| digit}
Extended BNF (continued…)
• For example, the previous example can be written in EBNF like
below:
• The braces above mean that its inner part may be repeated 0 or more
times. It frees your mind from getting lost in recursion.
Extended BNF (continued…)
• Everything you can express in EBNF can also be expressed in BNF.
• EBNF usually uses a slightly different notation than BNF. For
example:
Example:
thing = "water" [ "melon" ]
So the above thing is either water or watermelon.
Repetition
• With BNF we could not do that in one line. It would look like the
following in BNF:
<fly> ::= <type> "fly" <type> ::= "fire" | "fruit"
Parse Trees
• A hierarchical representation of a derivation. Every internal node of
a parse tree is labeled with a non terminal symbol; every leaf is
labeled with a terminal symbol.
• Every subtree of a parse tree describes one instance of an abstraction
in the sentence
Parse Trees(continued…)
• A grammar is ambiguous if it generates a sentential form that has two or
more distinct parse trees An ambiguous expression grammar:
<expr> -> <expr> <op> <expr> | const
<op> -> / | -
• If we use the parse tree to indicate precedence levels of the operators, we
cannot have ambiguity An unambiguous expression grammar:
<expr> -> <expr> - <term> | <term>
<term> -> <term> / const | const
Example