Principal Programming Language (RGPV)
Principal Programming Language (RGPV)
Subject Notes
Department of Computer Science and Engineering
Subject Name: PPL Subject Code:CS6002
Unit-1
Language Evaluation Criteria
The following factors influences Language evaluation criteria
1) Readability 2) Simplicity 3) Orthogonality 4) Writability 5) Reliability 6) Cost
1. Readability
• One of the most important criteria for judging a programming language is the ease with which programs
can be read and understood.
• Language constructs were designed more from the point of view of the computer than of computer users
2. Overall simplicity
• Language with too many features is more difficult to learn
• Feature multiplicity is bad. For example: In Java, increment can be performed if four ways as:
Count= count+1
Count+=1
Count++
++count
• Next problem is operator overloading, in which single operator symbol has more than one meaning.
3. Orthogonality
• A relatively small set of primitive constructs that can be combined in a relatively small number of ways
• Consistent set of rules for combining constructs (simplicity)
• Every possible combination is legal
• For example, pointers should be able to point to any type of variable or data structure
• Makes the language easy to learn and read
• Meaning is context independent
• Lack of orthogonality leads to exceptions to rules
• C is littered with special cases
Orthogonality is closely related to simplicity. The more orthogonal the design of a language, the fewer
exceptions the language rules require. Fewer exceptions mean a higher degree of regularity in the design,
which makes the language easier to learn, read, and understand.
– Useful control statements
– Ability to define data types and structures
– Syntax considerations
4. Writability - Writability is a measure of how easily a language can be used to create programs for a chosen
problem domain and can be directly related to:
– Most readability factors also apply to writability
– Simplicity and orthogonality
– Control statements, data types and structures
– Support for abstraction
5. Reliability-
A program is said to be reliable if performs to its specifications under all conditions.
Type checking
• Type checking is simply testing for type errors in a given program, either by the compiler or during the
program execution
• Because run time type checking is expensive, compile time type checking is more desirable
• Famous failure of space shuttle experiment due to int / float mix-up in parameter passing.
Exception handling
• A ility to intercept run-time errors
• A ility to use different names to reference the same memory
• A dangerous feature
6. Cost-
The cost is also an important language evaluation criteria. The total cost of a programming is a function of cost
of training to programmers, cost of writing programs, cost of compiling programs, cost of executing programs,
cost of maintaining programs.
structured programming
Programming Methodologies Influences
Scientific applications-– Large number of floating point computations. The most common data structures
Programming Domain
are arrays and matrices; the most common control structures are counting loops and selections. The first
language for scientific applications was FORTRAN, ALGOL 60 and most of its descendants. Examples of
languages best suited: Mathematica and Maple.
• Business applications- Business languages are characterized by facilities for producing reports, precise
ways of describing and storing decimal numbers and character data, and ability to specify decimal arithmetic
operations. Its uses for decimal numbers and characters. COBOL is the first successful high-level language for
those applications.
• Artificial intelligence- In AI Symbols rather than numbers are typically manipulated. 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. The first AI language was LISP and is still most
widely used
• Systems programming- The operating system and all of the programming support tools of a computer
system are collectively known as systems software. It needs for efficiency because of continuous use and low-
level features for interfaces to external devices
• Special-purpose languages
– RPG (Report Program Generator) : business reports
– APT (Automatically Programmed Tool) programmable machine tools
– GPSS (General Purpose Simulation System ) : simulation
Language Categories-
The four categories usually recognized are imperative, object-oriented, functional, and logic. Each Language
category has some special features.
Programming Paradigms
1. Imperative- imperative programming is a programming paradigm that uses statements that change a
program's state.
In much the same way that the imperative mood in natural languages expresses commands, an imperative
program consists of commands for the computer to perform. Imperative programming focuses on
describing how a program operates.
Examples: C, Pascal
2. Object-oriented-Stands for "Object-Oriented Programming." OOP refers to a programming methodology
based on objects, instead of just functions and procedures. These objects are organized into classes, which
allow individual objects to be group together. Most modern programming languages including Java, C/C++,
and PHP, are object-oriented languages, and many older programming languages now have object-oriented
versions.
An "object" in an OOP language refers to a specific type, or "instance," of a class. Each object has a structure
similar to other objects in the class, but can be assigned individual characteristics. An object can also call
functions, or methods, specific to that object. For example, the source code of a video game may include a
class that defines the structure of characters in the game. Individual characters may be defined as objects,
which allow them to have different appearances, skills, and abilities. They may also perform different tasks in
the game, which are run using each object's specific methods.
Examples: Java, C++
3. Functional-Functional programming languages are specially designed to handle symbolic computation and
list processing applications. Functional programming is based on mathematical functions. Some of the popular
functional programming languages include: Lisp, Python etc.
Examples: LISP, Scheme
Functional programming languages are categorized i to t o g oups, i.e. −
Pure Functional Languages − these t pes of fu tio al la guages suppo t o l the fu tio al pa adig s. Fo
e a ple − Haskell.
Impure Functional Languages − these t pes of fu tio al la guages suppo t the fu tio al pa adig s a d
impe ati e st le p og a i g. Fo e a ple − LI“P.
execution of a logic program corresponds to the construction of a proof of the goal statement from the
axioms.
Example: Prolog
Source Code
Lexical Analyser
Syntax Analyser
Intermediate Code
Symbol Generator Error
Table Handler
Machine Independent
Code optimizer
Target Code
Source program
Input data
Interpreter
Result
Figure 1.2 Pure Interpretation Process
Source Code
Lexical Analyzer
Syntax Analyzer
Intermediate Code
Generator
Input data
Interpreter
Programming Environments-
Integrated Development Environments
An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities
to computer programmers for software development. An IDE normally consists of a source code editor, build
automation tools and a debugger. Most modern IDEs have intelligent code completion. Some IDEs, such
as NetBeans and Eclipse, contain a compiler, interpreter, or both. The boundary between an integrated
development environment and other parts of the broader software development environment is not well-
defined. Sometimes a version control system and various tools to simplify the construction of a Graphical User
Interface (GUI) are integrated. Many modern IDEs also have a class browser, an object browser, and a class
hierarchy diagram, for use in object-oriented software development.
are the following: Lexical analysis (scanning), syntactic analysis (parsing), and Semantic analysis. There are four
functions in semantic analysis. These as follows:
1. Symbol-table maintenance.
2. Insertion of implicit information.
3. Error detection
4. Macro processing and compile-time operations.
Macro is a set of keystrokes and instructions recorded and saved under a short key code. When the key code is
typed, the program carries out the instructions of the macro. Program users create macros to save time by
replacing often-used, sometimes lengthy, series of strokes with shorter versions. A compile-time operation is
an operation to be performed during translation to control the translation of the source program.
Synthesis of the Object Program- The final stages of translation are concerned with the construction of the
executable program from the outputs produced by the semantic analyser. It is composed of
Optimization- The semantic analyser ordinarily produces as output the executable translated program
represented in some intermediate code.
Code generation- After the translated program in the internal representation has been optimized; it must be
formed into the assembly language statements, machine code, or other object program form that is to be the
output of the translation.
Linking and loading- In the optional final stage of translation, the pieces of code resulting from separate
translations of subprograms are coalesced into the final executable program.
Formal Translation models- The formal definition of the syntax of a programming language is usually
called grammar. Grammar is a branch of linguistics dealing with the form and structure of words
(morphology), and their interrelation in sentences (syntax). The study of grammar reveals how language
works.
Context Free Grammar- A context-free grammar (CFG) consisting of a finite set of grammar rules is a quadruple
Example
The g a a {A}, {a, , }, P, A , P : A → aA, A → a .
The g a a {“, a, }, {a, }, P, “ , P: “ → a“a, “ → “ , “ → ε
The g a a {“, F}, { , }, P, “ , P: “ → “ | F, F → F | ε
Bacus-Naur form is a notation which can be used to give inductive specifications for the syntactic elements of a
language. The problem we face when we wish to define the rules of syntax (grammar) of a language is that we
have to use notation (often involving the same alphabet as used in the language) to describe the rules for
forming strings of symbols. We need to be able to distinguish symbols appearing in the syntax rule which are
part of the rule itself from symbols which are part of a properly formed string of the language. Bacus and Naur
developed a notational scheme, called BNF, for such syntax descriptions.
BNF can be used to inductively define a number of sets of syntactic elements of a language at once. These sets
are called syntactic categories, or sometimes nonterminals and we write the names of these sets by enclosing
them in "<" ">" . For example, the list_of_numbers J data type would be a nonterminal and would be written
as <list_of_numbers>. Each syntactic category is defined by a finite set of rules, or productions. Each rule
asserts that certain values must be in the syntactic category.
Example 1
Here is the BNF definition of the list-of-numbers syntax. This description has two rules.
X Y Z
E + E
E E * E
id id
Figure 1.5 Example of Parse Tree
Example: Given the following grammar, find a parse tree for the string 1 + 2 * 3:
<E> --> <D>
<E> --> ( <E> )
<E> --> <E> + <E>
<E> --> <E> - <E>
<E> --> <E> * <E>
<E> --> <E> / <E>
<D> --> 0 | 1 | 2 | ... 9
The parse tree is:
E --> E --> N --> 1
+
E --> E --> N --> 2
*
E --> N --> 3