PPL Unit-I
PPL Unit-I
PPL Unit-I
Preliminary Concepts
Reasons for Studying of Programming Languages
Increased capacity to express ideas:
• People can easily express their ideas clearly in any language only when they
have clear understanding of the natural language.
• Similarly, if programmers want to simulate the features of languages in another
language, they should have some ideas regarding the concepts in other languages as
well.
Improved background for choosing appropriate languages
• If these programmers were familiar with a wider range of languages, they would
be better able to choose the language that includes the features that best address the
characteristics of the problem at hand.
• There is a global view of computing that can justify the study of programming
language concepts.
• For example, many people believe it would have been better if ALGOL 60 ha
displaced Fortran in the early 1960s, because it was more elegant and had much better control
statements than Fortran. That it did not is due partly to the programmers and software development
managers of that time, many of whom did not clearly understand the conceptual design of ALGOL
60.
• If those who choose languages were better informed, perhaps, better languages
would eventually squeeze out poorer ones.
– Large number of floating point computations. The most common data structures
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 descedants
– Examples of languages best suited: Mathematica and Maple
• Business applications
• Artificial intelligence
– 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
– First AI language was LISP and is still most widely used
– Alternate languages to LISP are Prolog – Clocksin and Mellish
• Systems programming
– The operating system and all of the programming support tools of a computer
system are collectively known as systems software
– Need for efficiency because of continuous use
– Low-level features for interfaces to external devices
– C is extensively used for systems programming. The UNIX OS is written almost
entirely in C
• Web software
– Markup languages
• Such as XHTML
– Scripting languages
• Special-purpose languages
– RPG – business reports
– APT – programmable machine tools
– GPSS – simulation
• Language constructs were designed more from the point of view of the computer than
of computer users
• From 1970s, the S/W life cycle concept was developed; coding was relegated to a much
smaller role, and maintenance was recognized as a major part of the cycle, particularly
in terms of cost. Because ease of maintenance is determined in large part by readability
of programs, readability became an important measure of the quality of programs
Overall simplicity
• Language with too many features is more difficult to learn
Orthogonality
Orthogonolity 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
• Provision for descriptive identifiers
Writability
– Most readability factors also apply to writability
– Simplicity and orthogonality
– Control statements, data types and structures
– Support for abstraction
• Data abstraction
• Process abstraction
– Expressivity
• It is easy to express program ideas in the language
• APL is a good example
• In C, the notation C++ is more convenient and shorter than C = C + 1
• The inclusion of for statement in Java makes writing counting loops easier
than the use of while
• 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
– Cost
– Training programmers to use language
– Writing programs in a particular problem domain
– Compiling programs
– Executing programs
– Language implementation system (free?)
– Reliability
– Maintaining programs
– Others: portability, generality, well-definedness
Influences on Language Design
Computer Architecture
– Languages are developed around the prevalent computer architecture, known as the von
Neumann architecture
• Programming Methodologies
– New software development methodologies (e.g., object oriented software development) led
to new programming paradigms and by extension, new programming languages.
• Iteration is efficient
repeat forever
fetch the instruction pointed by the
counter
increment the counter decode
the instruction execute the
instruction end repeat
• 1950s and early 1960s: Simple applications; worry about machine efficiency
• Late 1960s: People efficiency became important; readability, better control structures
– structured programming
– top-down design and step-wise refinement
• Late 1970s: Process-oriented to data-oriented
– Data abstraction
Language Categories
• Imperative
– Central features are variables, assignment statements, and iteration
– Examples: C, Pascal
• Functional
– Main means of making computations is by applying functions to given parameters
– Examples: LISP, Scheme
• Logic (declarative)
– Rule-based (rules are specified in no particular order)
– Example: Prolog
• Object-oriented
– Data abstraction, inheritance, late binding
– Examples: Java, C++
• Markup
– New; not a programming per se, but used to specify the layout of information in Web
documents
– Examples: XHTML, XML
Language Design Trade-Offs
Translates whole source code into object code at a time and generate errors at the end . If no
errors ,generates object code. The object code after linking with libraries generates exe code.
User input will be given with execution.
Ex: C++ is a compiler
Pure Interpretation Process Ttranslation of source code line by line so that generates errors
line by line.If no errors in the code generates object code. While interpretation it selef user
input will be given.
• Pre-processor macros (instructions) are commonly used to specify that code from another
file is to be included
• A pre-processor processes a program immediately before the program is compiled to
expand
embedded pre-processor macros
• A well-known example: C pre-processor
– expands #include, #define, and similar macros
Programming Environments’
• Syntax: the form or structure of the expressions, statements, and program units
• Semantics: the meaning of the expressions, statements, and program units
• Pragmatics:
• Syntax and semantics provide a language’s definition
– Users of a language definition
Other language designers
Implementers
Programmers (the users of the language)
Terminology
• A metalanguage is a language used to describe another language
• A sentence is a string of characters over some alphabet
• A lexeme is the lowest level syntactic unit of a language (e.g., *, sum, begin)
• Recognizers
– Read a string and decide whether it follows the rules for the language
– Example: syntax analysis part of a compiler
• Generators
– A device that generates sentences of a language (BNF)
– More useful for specifying the language than for checking a string
Syntax
BNF Rules
A rule has a left-hand side (LHS) and a right-hand side (RHS), and consists of terminal and
nonterminal symbols
An abstraction (or nonterminal symbol) can have more than one RHS
Derivations
• BNF is a generative device
– Use a grammar to generate sentences that belong to the language the grammar
describes
• A derivation is a repeated application of rules, starting with the start symbol and
ending with a sentence (all terminal symbols)
Derivation
• 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
An Example Grammar
<program> -> <stmts>
An Example Derivation
<program> => <stmts> => <stmt> => <var> = <expr> => a = <expr>
=> a = b + const
Parse Tree
– information about variable and expression types could be included in a grammar but only at
the cost of great complexity