PPL Unit-1 Part1
PPL Unit-1 Part1
1
5. Ability to design new languages:
• The more languages you gain knowledge of, the better understanding of programming
languages concepts you understand.
• Most professional programmers sometime design language of one kind or the other with
complete their needs & which is easy to learn and most efficient.
6. Better use of languages that are already known.
• Many contemporary programming languages are large and complex.
• Accordingly, it is uncommon for a programmer to be familiar with and use all of the
features of a language he or she uses.
• By studying the concepts of programming languages, programmers can learn about
previously unknown and unused parts of the languages they already use and begin to use
those features.
• Some languages are better for some jobs than others.
Example – FORTRAN and APL for calculations, COBOL and RPG for report generation, LISP
and PROLOG for AI, etc.
By understanding how features are implemented, you can make more efficient use of them.
Examples: • Creating arrays, strings, lists, records. • Using recursions, object classes, etc.
7. Overall advancement of computing:
• In some cases, a language became widely used, at least in part, because those in positions
to choose languages were not sufficiently familiar with Programming Language concepts.
• The popularity of programming language can be easily determined by the most popular
languages are not always the best available language.
• 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.
PROGRAMMING DOMAINS
programming domains defines the ability of using a specific language for a specific usage.
There are many programming domains, but let’s take the common domains:
1. Scientific Applications:
The first digital computers, which appeared in the late 1940s and early 1950s,
were invented and used for scientific applications. Typically, the scientific applications of that
time used relatively simple data structures, but required large numbers of floating
point arithmetic computations.
• The most common data structures were arrays and matrices.
• The most common control structures were counting loops and selections.
2
The early high-level programming languages invented for scientific applications were designed
to provide for those needs. Their competition was assembly language, so efficiency was a
primary concern. The main languages that were developed were FORTRAN, ALGOL 60.
2. Business Applications:
The use of computers for business applications began in the 1950s. Special computers were
developed for this purpose, along with special languages. Business languages are characterized
by facilities for producing elaborate reports, precise ways of describing and storing decimal
numbers and character data, and the ability to specify decimal arithmetic operations. The first
successful high-level language for business was COBOL(ISO/IEC, 2002), the initial version of
which appeared in 1960. It is still the most commonly used language for these applications.
There have been few developments in business application languages outside the
development and evolution of COBOL.
3. Artificial Intelligence:
AI is a broad area of computer applications characterized by the use of symbolic rather than
numeric computations.
• Symbolic computation means that symbols, consisting of names rather than numbers,
are manipulated.
• Also, symbolic computation is more conveniently done with linked lists of data rather
than arrays.
• This kind of programming sometimes requires more flexibility than other
programming domains.
For example, in some AI applications the ability to create and execute code segments during
execution is convenient.
The first widely used programming language developed for AI applications was the functional
language LISP.
4. Systems Programming:
The operating system and the programming support tools of a computer system are
collectively known as its systems software.
• Systems software is used almost continuously and so it must be efficient.
• Furthermore, it must have low-level features that allow the software interfaces to
external devices to be written.
The general programming languages, such as C and C++ are usually preferred for system
programming.
3
5. Web Software:
• The World Wide Web software is used to represent some dynamic web contents,
representation of text, audio or video data, contents containing some computations and so
on.
• It needs a support for variety of languages from markup languages (HTML), scripting
language (JavaScript/PHP), General purpose (Java).
6. Scripting Languages:
These languages have evolved over the last 25 years.
Characteristics: a) A scripting language is used by putting a list of commands, called a SCRIPT
in a title to be executed. b) For simple applications like file management and file filtering
Languages Developed:
I) SH is the first scripting language with simple commands later control, flow statements
variables, functions and other capabilities were added resulting in a complete programming
language
V) PERL
7. Special-Purpose Languages:
They have evolved over the past 40 years and these are designed for a particular specific
purpose Languages Develop
a) PPG to produce business reports
b) API- for instructing programmable machine tools
c) GPSS for system simulation.
These are not used that much because of their narrow applicability.
4
Simplicity: A large language takes more time to learn.
Data Types: Adequate facilities for defining data types and structures.
Support for Abstraction: means the ability to define and use complicated structures or operations
in ways that allow many of the details to be ignored.
Expressivity: The great deal of computation must be accomplished with a very small program.
Restricted Aliasing: referencing the same memory cell with more than one name.
READABILITY
The ease with which programs can be read and understood is called readability. The following
describe characteristics that contribute to the readability of a PL.
1) Simplicity-
a. The language that has large no. of basic components is more difficult to learn than one with a
small no of basic components.
b. The language should not have multiplicity of commands.
5
c. For e.g. I = I + 1 ; I + = 1 ;I + + ; + + I .
d. The language should not have operator overloading in which a single operator symbol has more
than one meaning.
2) Orthogonal –
It makes the language easy to learn and read-context independent.
a. It means that a relatively small number of primitive constructs can be combined in a number of
ways to build the program.
b. Orthogonal language is independent of the context of its appearance in the program.
3) Control Statements-
a. A program that can be read from top to bottom is much easier to understand than a program
that requires the reader to jump from one statement to some other non-adjacent statement.
b. Example- goto statements.
4) Data Types and Structures-
a. The presence of adequate facilities for defining data types and data structures in a language is
another significant aid to readability.
b. There should be provision for data structures in a language are another significant aid to
readability.
c. There should be provision for data types, for record type of data types (representing an array
of employee records)
5) Syntax considerations-
a. Syntax is the form of elements of language.
b. There are 3 types of syntactic design choices that affect readability. Different forms of
identifiers, special keywords (reserve words), Form & meaning – constructs that are similar in
appearance but different meaning is not readable.
WRITABILITY
The measure of how easily a language can be used to create programs for a chosen problem
domain. The features that affect the readability of a also affect the writ ability apart from them,
the factors that influence writability are
1) Simplicity-
a. A large language takes more time to learn.
b. Programmers might learn only a subset.
6
c. Feature multiplicity (having more than one way to perform a particular operation) is often
confusing.
d. For example, in C++ or Java you can decrement a variable in four different ways:
x = x – 1; x -= 1; x--; --x.
e. Operator overloading (a single operator symbol has more than one meaning) can lead to
confusion. Some languages (e.g. assembly languages), can be "too simple" – too low level. 2, 3, 4,
5 or more statements needed to have the effect of 1 statement in a high-level language
2) Orthogonality-
a. In general use, it means being independent, non-redundant, non-overlapping, or not related.
b. In computer languages, it means a construct can be used without consideration as to how its
use will affect something else.
c. A programming language is considered orthogonal if its features can be used without thinking
about how their use will affect other features, e.g. objects and arrays.
d. Having fewer constructs and having few exceptions increases readability and writability.
e. Orthogonal languages are easier to learn. Examples:Pointers should be able to point to any type
of variable or data structure.
3) Support for abstraction – process & data abstraction both.
a. Abstraction means the ability to define and use complicated structures or operations in ways
that allow many of the details to be ignored.
b. For example- To use a subprogram to implement a sort algorithm that is required several times
in a program.
c. Without the subprogram the sort code would have to be replicated in all places where it was
needed, which would make the program much longer and more tedious to write.
4) Expressivity-
a. The great deal of computation must be accomplished with a very small program.
b. A language must have relatively convenient, rather than cumbersome ways of specifying
computations.
c. For example, in C, the statement count++ is more convenient and shorter than count=count+1.
d. Also, the use of for statement in Java makes writing counting loops easier than with the use of
while, which is also possible.
7
RELIABILITY
A program is said to be reliable if it performs to its specifications under all conditions. Along with
all the features that affect readability and writ-ability there are several other features that affect
reliability
1) Type checking –
It is the testing for type errors in a given program either by compiler or during program execution.
Runtime checking is expensive. Examples of failures of type checking (i)Countless loops(ii)Formal
and actual parameter being of different types(iii)Array out of bounds
2) Exception Handling –
The ability of a program to intercept run-time errors, take corrective measures and then continue
is a great aid to reliability. ADA, C++, Java include this capability whereas C, FORTRAN don’t.
3) Aliasing-
Aliasing is referencing the same memory cell with more than one name
E.g., in C, both x and y can be used to refer to the same memory cell
int x = 5;
int *y = &x;
Aliasing is a dangerous feature in a programming language.
COST
The ultimate cost of a programming language is a function of many of its characteristics
1. The cost of training programmers
2. The cost of writing programs
3. The cost of compiling programs
4. The cost of executing programs
5. The cost of Language implementation System
6. The cost of poor reliability
7. The cost of maintaining programs
8
INFLUENCES ON LANGUAGE DESIGN
The following factors that influence the evolution of programming language.
i. Computer architecture
The most commonly used computer architecture is “von Neumann machine” (or model). The
execution of a machine code program on a von Neumann architecture computer occurs in a
process called the fetch-execute-cycle.
• In 1950’s and early 1960’s Simple applications with limited machine efficiency were built.
• In later 1960’s the programming with better readability and better control structures were
developed. Then the structured programming approach is being adopted. A new
programming method developed called Top-down design and step-wise refinement
• Late 1970’s the programming with process-oriented to data-oriented methodology is
developed which is data abstraction.
• In middle 1980’s there is strong use of object-oriented methodology came into existence,
which is the extension of data-oriented methodology.
9
LANGUAGE CATEGORIES OR PROGRAMMING PARADIGMS
Programming Paradigm can be defined as a method of problem solving and an approach to
programming language design.
Programming languages are often categories as follows:
• Imperative or Procedural Programming Language.
• Functional Programming Language.
• Logic Programming Language.
• Object Oriented Programming Language.
10
Functional Programming Language:
• The language one in which the primary mean’s of making computation’s is by applying fun’s
to given parameters. These languages called functional language.
• In this paradigm the computations are expressed in the form of functions.
• Functional programming paradigms treat values as single entities. Unlike variables, values
never modified.
• Functional programming languages are a class of languages designed to reflect the way
programmers think mathematically, not reflecting the underlying machine.
• Functional languages are based on the lambda calculus, a simple model of computation,
and have a solid theoretical foundation that allows one to reason formally about the
programs written in them.
• The most commonly used functional languages are Standard LISP (List processing), ML,
Haskell, and “pure” Scheme.
Merits:
• The functions ate not reusable.
• It is possible to develop and maintain large programs.
• Because of usage of functions programs are easy to understand.
Demerits:
• Functional programming is less efficient.
• Functional programming concept is not good option for commercial software
development.
Logic Programming Language:
11
Object Oriented Programming Language:
• The language in which objects are used. Object have both data member and member
function. Object concept is used in place of procedures. These languages are called object-
oriented programming language.
• OOP not consider the separate category of the PL. OOP naturally develop from imperative
languages.
• In this language everything is modelled as object.
• This language has modular programming approach in which data and functions are
bounded in one entity called class.
• This programming paradigm has gained a great popularity in recent ears because of
characteristic features such as data abstraction, encapsulation, inheritance, polymorphism
and so on.
• Examples of object-oriented programming languages are Smalltalk, C++, Java.
Merits:
• Re-usability
• Data Redundancy
• Security
• Code Maintenance
• Objects can be created for real world entities.
• Readability vs. writability: If program is readable then it is probably not writable or vice versa.
Another conflicting criteria – Example: APL provides many powerful operators for array operands
(and a large number of new symbols), allowing complex computations to be written in a compact
program but at the cost of poor readability. Many ALP operators can be used in a single long
complex expression. APL is very writable but poor readability.
• Writability (flexibility) vs. reliability: If program is flexible then it is probably not safe or vice versa
– Another conflicting criteria – Example: C++ pointers are powerful and very flexible but not reliably
used. Because of the potential reliability problems with pointers, they are not included in Java.
12
IMPLEMENTATION METHODS
the primary components of a computer are its internal memory and its processor. The internal
memory is used to store programs and data. The processor is a collection of circuits that provides
a realization of a set of primitive operations, or machine instructions, such as those for arithmetic
and logic operations. In most computers, some of these instructions, which are sometimes called
macroinstructions.
A language implementation system cannot be the only software on a computer. Also required is a
large collection of programs, called the operating system, which supplies higher-level primitives
than those of the machine language These primitives provide system resource management, input
and output operations, a file management system, text and/or program editors, and a variety of
other commonly needed functions. Because language implementation systems need many of the
operating system facilities, they interface with the operating system rather than directly with the
processor (in machine language).
13
The operating system and language implementations are layered over the machine language
interface of a computer. These layers can be thought of as virtual computers, providing interfaces
to the user at higher levels. For example, an operating system and a C compiler provide a virtual C
computer. With other compilers, a machine can become other kinds of virtual computers. Most
computer systems provide several different virtual computers. User programs form another layer
over the top of the layer of virtual computers.
COMPILATION
Programming languages can be implemented by any of three general methods. At one extreme,
programs can be translated into machine language, which can be executed directly on the
computer. This method is called a compiler implementation and has the advantage of very fast
program execution, once the translation process is complete. Most production implementations
of languages, such as C, COBOL, C++, and Ada, are by compilers. The language that a compiler
translates is called the source language. The process of compilation and program execution takes
place in several phases, the most important of which are shown in Figure.
Compilation process has several phases:
lexical analysis:
• This is an initial phase of compilation in which each statement in the source program is
scanned or read line by line and then it broken into stream of string called tokens. lexical
analysis phase is also called as scanning.
• The lexical analyzer gathers the characters of the source program into lexical units. The
lexical units of a program are identifiers, special words, operators, and punctuation
symbols.
• The lexical analyzer ignores comments in the source program because the compiler has no
use for them.
• The lexical analyzer identifies the type of each lexeme and store it’s information in the
symbol table.
14
Syntax analysis:
• This is the second phase in the process of compilation.
• The syntax analyzer takes the lexical units from the lexical analyzer and uses them to
construct hierarchical structures for checking the syntax of source code called parse trees.
• These parse trees represent the syntactic structure of the program.
• It is also called as parsing as the parse tree is constructed in this phase.
Semantics analysis:
• The semantic analyzer is a phase in which the meaning of source program is analyzed.
• The semantic analyzer is an integral part of the intermediate code generator.
• The semantic analyzer checks for errors, such as type errors, that are difficult, if not
impossible, to detect during syntax analysis.
Code Optimization:
• Semantic analyzer produces the code called intermediate code. For example consider the
statements
a=b+c-d
The intermediate code can be generated as follows.
t1=b+c
t2=t1-d
a=t2
• Optimization, which improves programs (usually in their intermediate code version) by
making them smaller or faster or both, is often an optional part of compilation.
Code generation:
• The code generator translates the optimized intermediate code version of the program into
an equivalent machine language program.
• The output code produced during this phase can be directly executed or may be other
translation step required to follow.
• These steps can be assembly, linking and loading.
Symbol table:
• The symbol table serves as a database for the compilation process.
• The primary contents of the symbol table are the type and attribute information of each
user-defined name in the program.
• This information is placed in the symbol table by the lexical and syntax analyzers and is used
by the semantic analyzer and the code generator.
15
• The user and system code together are sometimes called a load module, or executable
image.
• The process of collecting system programs and linking them to user programs is
called linking and loading, or sometimes just linking. It is accomplished by a systems
program called a linker.
16
2. These translated modules are linked together in a relocatable unit. This task is carried out by
linker or linkage editor.
3. Finally the complete program is loaded into the memory as an executable machine code. This
task is carried out by loader.
The modern translation technique uses the combined two technique - translation and then
interpretation. That means the source code is translated into intermediate code and then the
intermediate code is interpreted.
17
In addition to systems programs, user programs must often be linked to previously compiled user
programs that reside in libraries. So the linker not only links a given program to system programs,
but also it may link it to other user programs.
The speed of the connection between a computer’s memory and its processor usually determines
the speed of the computer, because instructions often can be executed faster than they can be
moved to the processor for execution. This connection is called the von Neumann bottleneck.
it is the primary limiting factor in the speed of von Neumann architecture computers. The von
Neumann bottleneck has been one of the primary motivations for the research and development
of parallel computers.
Interpreter Compiler
The source program gets interpreted every In the process of compilation, the program is
time it is to be executed, and every time the analyzed only once and then the code is
source program is analyzed. Hence generated. Hence compiler is efficient than
interpretation is less efficient than Compiler. interpreter.
The interpreters do not produce object code. The compilers produce object code.
The interpreters can be made portal because The compilers has to be present on the host
they do not produce object code. machine when particular program needs to
be compiled.
Interpreters are simpler and give us improved The compiler is a complex program and it
debugging environment. requires large amount of memory
PURE INTERPRETATION
Pure interpretation lies at the opposite end (from compilation) of implementation methods. With
this approach, programs are interpreted by another program called an interpreter, with no
translation whatever.
• Pure interpretation has the advantage of allowing easy implementation of many source-
level debugging operations, because all run-time error messages can refer to source-level
units. For example, if an array index is found to be out of range, the error message can
easily indicate the source line and the name of the array.
• On the other hand, this method has the serious disadvantage that execution is 10 to 100
times slower than in compiled systems.
• The primary source of this slowness is the decoding of the high-level language statements,
which are far more complex than machine language instructions (although there may be
fewer statements than instructions in equivalent machine code).
18
• Furthermore, regardless of how many times a statement is executed, it must be decoded
every time. Therefore, statement decoding, rather than the connection between the
processor and memory, is the bottleneck of a pure interpreter.
Although some simple early languages of the 1960s (APL, SNOBOL, and LISP) were purely
interpreted, by the 1980s, the approach was rarely used on high-level languages. However, in
recent years, pure interpretation has made a significant comeback with some Web scripting
languages, such as JavaScript and PHP, which are now widely used. The process of pure
interpretation is shown in Figure
19
– Initial implementations of Java were hybrid, the intermediate form, byte code, provides
portability to any machine that has a byte code interpreter and a runtime system (together, these
are called Java Virtual Machine)
20
PREPROCESSER
Definition: Preprocessor is a program that processes a program just before the program is
compiled.
• Preprocessor instructions are embedded in the program.
• Preprocessor macros (instructions) are commonly used to specify that code from another
file is to be included.
• For example: The C preprocessor expands #include or #define in the following manner –
➢ #include "myLib.h"
causes the preprocessor to copy the contents of mylib.h into the program at the
position of the #include.
➢ #define SIZE 5
In the program we can declare an array of size 5 in following manner- int a[SIZE];
➢ #define max(A, B) ((A) > (B) ? (A) : (B))
Other preprocessor instructions are used to define symbols to represent
expressions.
PROGRAMMING ENVIRONMENTS
Programming environment is an environment in which the programs can be created and tested.
A programming environment is the collection of tools used in the development of software. This
collection may consist of only a file system, a text editor, a linker, and a compiler. A programming
language are not the only measure of the software development capability of a system. We now
briefly describe several programming environments.
➢ UNIX is an older programming environment, first distributed in the middle 1970s, built
around a portable multiprogramming operating system. It provides a wide array of
powerful support tools for software production and maintenance in a variety of
languages. In the past, the most important feature absent from UNIX was a uniform
interface among its tools. This made it more difficult to learn and to use. However, UNIX is
now often used through a graphical user interface (GUI) that runs on top of UNIX. Examples
of UNIX GUIs are the Solaris Common Desktop Environment (CDE), GNOME, and KDE.
These GUIs make the interface to UNIX appear similar to that of Windows and Macintosh
systems.
➢ Borland JBuilder is a programming environment that provides an integrated compiler,
editor, debugger, and file system for Java development, where all four are accessed through
a graphical interface. JBuilder is a complex and powerful system for creating Java software.
➢ Microsoft Visual Studio .NET is a relatively recent step in the evolution of software
development environments. It is a large and elaborate collection of software development
tools, all used through a windowed interface. This system can be used to develop software
21
in any one of the five .NET languages: C#, Visual BASIC .NET, JScript (Microsoft’s version of
JavaScript), F# (a functional language), and C++/CLI.
➢ NetBeans is a development environment that is primarily used for Java application
development but also supports JavaScript, Ruby, and PHP. Both Visual Studio and NetBeans
are more than development environments—they are also frameworks, which means they
actually provide common parts of the code of the application.
The programming environment influence on language design in two major areas namely separate
compilation and testing and debugging.
1. Separate compilation:
• There are varying number of programmers working on design, code and test the parts of
programs. This require the language to structured so that individual subprograms or other
parts can be separately compiled and executed without requirement of other part.
• Separate compilation is difficult because compiling one subprogram may need some
information which is present in some other sub program or sometimes shared data is also
used in the program due to which separate compilation is not possible. To solve this
problem, some languages have adopted certain features that aid separate compilation.
These features can be
1. Use of keyword extern
2. Use of scoping rules.
3. In object-oriented programming, the feature like inheritance can be used to use the
shared data.
22