0 ratings 0% found this document useful (0 votes) 148 views 361 pages Principle of Programming Language
The document outlines the syllabus for the 'Principles of Programming Languages' course at Savitribai Phule Pune University, detailing various programming paradigms, data structures, and Java programming concepts. It emphasizes the importance of understanding programming languages in engineering and provides a structured approach to learning through logical explanations, illustrations, and practical examples. The book is designed for students and teachers, ensuring comprehensive coverage of the subject matter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Carousel Previous Carousel Next
Save Principle of Programming Language For Later SUBJECT CODE : 210955
As per Revised Syllabus of
SAVITRIBA] PHULE PUNE UNIVERSITY
Choice Based Credit System (CBCS)
S.E. (Computer) Semester - IV
PRINCIPLES OF
PROGRAMMING LANGUAGES
Anuradha A. Puntambekar
ME. (Compuier)
Formerly
PE.S. Modem College of Engineering
Dr. Jyoti Rao
Ph. D. (Computer Engineering)
Professor in Computer Engineering Department
Dr. BLY. Patil Institute of Technology,
Pimpri, Pune
TECHNICAL |
2 PUBLICATIONS
{see sso ‘An Up-Thrust for Knowledge
@PRINCIPLES OF PROGRAMMING LANGUAGES
Subject Code : 210255
S.E. (Computer) Semester - IV
© Copyright with Anuradha A. Puntambekor
(printed and ebook version) reserved with Technical Publications. No part of this book
‘ould be reproduced in any form, Electronic, Mechanical, Photocopy or any information storage and
ut prior permission in writing, from Technical Publications, Pune.
Published oy
Printer
Yost Printers & Bindes
SNe. 10/14
Ghule Indus Estate, Nanded Vilage Road
Ta. - Havel, Dat, - Pune - 41104
-93-907 70-06
ee sPPU 19
a,PREFACE
The importance of Principles of Programming Languages is well known in various
engineering fields. Overwhelming response to our books on various subjects inspired us to
write this book. The book is structured to cover the key aspects of the subject Principles of
Programming Languages.
The book uses plain, Iucicl fanguage to explain fundamentals of this subject. The book
provides logical method of explaining various complicated concepts and stepwise methods
to explain the important topics. Each chapter is well supported with necessary illustrations,
practical examples and solved problems, All chapters in this book are arranged in a proper
sequence that permits each topic to build upon earlier studies. All care has been taken to
make students comfortable in understanding the basic concepts of this subject.
Representative questions have been added at the end of each section to help the
students in picking important points from that section.
The book not only covers the entire scope of the subject but explains the philosophy of
the subject. This makes the understanding of this subject more clear and makes it more
interesting. The book will be very useful not only to the students but also to the subject
teachers, The students have to omit nothing and possibly have to cover nothing more.
We wish to express our profound thanks to all those who helped in making this book a
reality, Much needed moral support and encouragement is provided on numerous
occasions by our whole family. We wish to thank the Publisher and the entire team of
Technical Publications who have taken immense pain to get this book in time with quality
printing
Any suggestion for the improvement of the book will be acknowledged and well
appreciated
Aathors
A. A. Puntambekar
De. (yeti Rao
Dedicated to God.SYLLABUS
Principles of Programming Languages - 210255
Credit Scheme Examination Scheme and Marks
Mid_Semester (TH) : 30 Marks
os, End_Semester (TH): 70 Marks
Unit! Fundamentals of Programming
Importance of Studying Programming Languages, History of Programming Languages, Impact of
Programming Paradigms, Role of Programming Languages, Programming Environments. Impact of
Machine Architectures: The operation of a computer, Virtual Computers and Binding Times.
Programming paradigms - Introduction to programming paradigms, Introduction to four main
Programming paradigms- procedural, object oriented, functional, and logic and rule based
(Chapter - 1)
Unit II Structuring the Data, Computations and Program
Elementary Data Types : Primitive data Types, Character String types, User Defined Ordinal Types,
Array types, Associative Arrays, Record Types, Union Types, Pointer and reference Type
Expression and Assignment Statements : Arithmetic expression, Overloaded Operators, Type
conversions, Relational and Boolean Expressions, Short Circuit Evaluation, Assignment Statements,
Mixed mode Assignment, Statement level Control Statements Selection Statements, Iterative
Staiements, Unconditional Branching. Subprograms : Fundamentals of Sub Programs, Design
Issues for Subprograms, Local referencing Environments, Parameter passing methods.
Abstract Data Types and Encapsulation Construct : Design
ues for Abstraction, Paramet:
Abstract Data types, Encapsulation Constructs, Naming Encapsulations. (Chapter - 2)
Unit M1 Java as Object Oriented Programming Language-Overview
Fundamentals of JAVA, Arrays : one dimensional a{ti-cimensional array. alternative arra
Fray, m
declaration statements,
String Handling : String class methods, Classes and Methods : class fundamentals, declaring
objects, assig
ing object reference variables, adding methods to a class, returning a value,constructors, this keyword, garbage collection, finalize method, overloading methods, argument
pas ject as parameter, returning objects, access control, static, final, nested and inner classes,
ing,
command line arguments, variable - length arguments. (Chapter - 3)
Unit IV Inheritance, Packages and Exception Handling using Java
Inheritances : member access and inheritance, super class references, Using super, multilevel
hierarchy, constructor call sequence, method overriding, dynamic method dispatch, abstract
classes, Object class,
Packages and Interfaces ; defining a package,
ding packages and CLASSPATH, access
protection, importing packages, interfaces (lefining, implementation, nesting, applying). variables
in interfaces, extending interfaces, instance of operator. Fundamental, exception types, uncauught
exceptions, try, catch, throw, throws, finalfy, multiple catch clauses, nested try statements, built-in
exceptions, custom exceptions (creating your own exception sub classes)
Managing Y/O : Streams. Byte Streams and Character Streams, Predefined Streams, Reading
cor
ole Input, Writing Console Output, Print Writer class. (Chapter - 4)
Unit V Multithreading in Java
Concurrency and Synchronization, Java Thread Model : Thread priorities, Synchronization
Mes
‘aging, Main Thread, Creating thread: Implementing Thread using thread class and Runnable
interface, Creating multiple threads using is Alive() and join.
Web Based Application in Java : Use of JavaScript for creating web based applications in Java
Introduction to Java script frameworks- ReactlS, JuelS, AngularJS (open source). (Chapter - 5)
Unit VI Logical and Functional Programming
Functional Programming Paradigm : Understanding symbof manipulation, Basic LISP functions.
a
initions, predicates, conditionals and scoping, Recursion and iteration, Properties List array and
acces
functions, Using lambda definitions, printing, reading and atom manipulation.
Logic Programming Paradigm : An Overview of Prolog, Syntax and Meaning of Prolog Programs,
Lists, Operators, Arithmetic, Using Structures. (Chapter - 6)TABLE OF CONTENTS
rs
Chapter- 1 Fundamentals of Programming (1 - 1) to (1 - 26)
1.1 Importance of Studying Programming Languages ......ssnsnesnnnnannarnne 1-2
1.2 History of Programming Languages. 1-3
1.3 Role of Programming Languages... 1-4
1.3.1 Evolution of Major Programming Languages 0:1 eve
1.3.2 Attributes of Good Language......
1.4 Programming Environments...
1.4.1 Effect on Language Design.....een sia nai ponocercirpcmnapinicggreng tnd)
1.4.2 Environment Framework...
1.5 Impact of Machine Architectures...
1.5.1 Operation of a Computer ..
1.5.2 Translators and Virtual Architectures.
1.5.3 Methods of Program Implementation
1.5.4 Virtual Computers
1.5.5 Binding and Binding Times .......
1.6 Programming Paradigms...
1.6.1 Imperative Programming.
1.6.2 Object Oriental Programming... isdn Biiadlnea ecu sntdringany des 20
1.6.3 Functional Programming 1-21
1.6.4 Logic Programming 1-21
1.7 Multiple Choice Questions with Answers ....Chapter-2 Structuring the Data, Computations and Program
(2 - 1) to (2 - 52)
2.1 Elementary Data Types
2.1.1 Primitive Data Types 2-2
2.1.2 Character String Types. 2-6
2.1.2.1 Design Issues... Cs es 2-6
2.1.2.2 String Operation 2-7
2.1.2.3 String Length Options... Leonean wud 7
2.1.2.4 Implementation of Character String Type... . masta
2.1.3 User Defined Ordinal Types 2-8
2.1.4 Array Types 2-9
2.1.4.1 Design Issues 2-10
2.1.4.2 Subscript Binding for Arrays. 2-10
2.1.4.3 Array Categories based on Subscript Binding... 2-10
2.1.4.4 Heterogeneous Array 2-11
2.1.45 Array Initialization 2-11
2.1.4.6 Array Operations enn ae 22-11
2.1.4.7 Rectangular and Jagged Arrays. 2-12
2.1.48 Slices. i i 2-12
2.1.5 Associative Arrays. ae ee 2-13
2.1.6 Record Types
2.17 Union Types...
2.1.7.1 Design Issues .. 2-15
2.1.7.2 Discriminated and Free Unions ‘ ts isi PPAS:
2.1.7.3 ADA Union Types... cman 2-15
2.1.8 Pointer and Reference Types... sehr r son 2216
2.1.8.1 Design Issues won. < 2-17
2.1.8.2 Point Operations ... . 2-17
2.1.8.3 Pointer Problems... . se 2-19
2.1.8.4 Pointers in Various Languages... es 2-192.1.8.5 Reference Type.
2.2 Expression and Assignment Statements....
2.2.1 Arithmetic Expressions
2.2.1.1 Design Issues
2.2.1.2 Precedence and Associativity
2.2.1.3 Operand Evaluation Order
2.2.2 Overloaded Operators.
2.2.3 Type Conversion
2.2.4 Relational and Boolean Expression
2.2.5 Short Circuit Evaluation
2.2.6 Assignment Statement
2.2.7 Mixed Mode Assignment...
2.3 Statement-level Control Statements...
2.3.1 Selection Statements...
2.3.2 Iterative Statements.
2.3.2.1 Counter Controlled Loops.
2.3.2.2 Logically Controlled Loops.
2.3.2.3 User-located Loop Control Mechanism.
2.3.2.4 Examples of Looping in ....
2.3.3 Unconditional Branching
2.4 Subprogram...
2.4.1 Fundamentals of Subprogram
2.4.1.1 General Subprogram Characteristics.
2.4.1.2 Basic Definitions
2.4.1.3 Procedure and Functions
2.4.2 Design Issues for Subprogram...
2.4.3 Local Referencing Environments .....0--sse
2.4.3.1 Local Variables.
2.4.3.2 Nested Subprogram...
2.4.4 Parameter Passing Methods
2.5 Abstract Data Types and Encapsulation Construct...
(wil)2.5.1 Design Issues For Abstraction, 2-42
2.5.2 Parameterized Abstract Data Types 2-42
2.5.3 Encapsulation Constructs ... : fe seve 22 A
2.5.4 Naming Encapsulations 2-45
2.6 Multiple Choice Questions with Answers
Uri se 04
2-46
Chapter-3 Java as Object Oriented Programming Language - Overview
(3 - 1) to (3 - 88)
3.1 Fundamentals of Java.......
3.1.1 Features Of JaVA sen
3.1.2 Difference between C, C++ and Java 3-5
3.2 Java Program Structure 3-7
3.3 How to Write a Java Program ? .. 3-8
3.4 Comments in Java...
3.5 Variables
3.6 Keywords ...
3.7 Data Types and Size......
3.8 Operators ......004
3.9 User Defined Data Types ..vsesnersnsratae
3.10 Control Statements......
3.11 Jump Statements.
3.12 Arrays...
3.12.1 One Dimensional Array...
3.12.2 Two Dimensional Array 3-36
3.13 String Handling... 3-39
3.13.1 Finding Length of String... 3-40
3.13.2 Concatenation 3-42
3.13.3 Character Extraction a . 3-423.13.4 String Comparison 3-43
3.13.5 Searching for the Substring 3-44
3.13.6 Replacing the Character from String 3-44
3.13.7 Upper Case and Lower Case 3-45
3.14 Classes and Methods....... 3-45
3.15 Objects...
3.16 Adding Methods to Class
3.17 Constructor...
3.17.1 Special Properties of Constructor...
3.17.2 Types of Constructors.
3.18 this keyword .... 3-57
3.19 Garbage Collection -60
3.20 finalize() Method ... -62
3.21 Overload Methods. -63
3,22 Argument Passing... -65
3.23 Object as Parameter .. - 66
3.24 Returning Object.....
3.25 Access Contrdl.... 3-68
3.26 Static Members. -70
3.27 Nested and Inner Class... wal
3.28 Command Line Argument...
3.29 Variable Length Arguments...
3.30 Multiple Choice Questions with Answers.Uni
iY
Chapter-4 Inheritance, Packages and Exception Handling using Java
(4-1) to (4 - 88)
Part
nhericance_|
4.1 Introduction to Inheritance ...
4.2 Types of Inheritance ...
4.3 Implementation of Single Inheritance.......
4.4 Member access and Inheritance...
4.5 Super Class Reference.
4.6 Using Super .. 11
4.7 Use of Final Keyword .... 4-13
4.7.1 Final Variables and Methods... 4-13
4.7.2 Final Classes to Stop Inheritance. 4-14
4.8 Multilevel Hierarchy...
4,9 Constructor Call Sequence.
4.10 Method Overriding.........
4.11 Polymorphism.
4.11.1 Dynamic Method Dispatch...
4.12 Abstract Classes 4-25
4.13 Object Class... -28
| Pare Il : Packages and Interfaces |
4.14 Defining a Package. 4-29
4.15 Finding Packages. 4-30
4.16 Adding Class to a Package... -31
4.17 CLASSPATH... +32
4.18 Access Protection... 4-334.19 Importing Packages. owe . . ” . 4-33
4,20 Nested Packages....
-33
4.21 JAVA API Package...
4,22 Interfaces
4.23 Variables in Interfaces .....
4.24 Extending Interfaces .. 4-46
4.25 Creation and Implementation of Interface........ stindlgnnnelinaptiy. 447:
4,26 Multiple Inheritance .
4.27 The Instance of Operator. 4-49
4.28 Fundamentals 4-51
4.28.1 Benefits of Exception Handling. caus soeeeten > SZ
4.28.2 Difference between Error and Exception 4-52
4.29 Exception Types... 4-52
4.30 try, catch, throw, throws and finally... sees 4-53
4.30.1 Handling try-catch BlOCK.wssccernssnee 4-54
4.30.2 Using finally 4-56
4.30.3 Using thrOWS ..ssssentnnnennsss disimtbiaditiehrendidisatisigilivd S57
4,31 Uncaught Exception... 4-58
4.32 Multiple Catch Clauses ....... ovhvosnvsenscessescsasvensoonsessssssnansecesneny wirtrdadsiriasasecs & > BO
4.33 Nested try Statements...
4,34 Built-in Exceptions...
4.35 Custom Exceptions .
Part IV: Managing 1/0
4.36 Streams...
4-69
4.37.1 Byte Stream 4-69
4.37 Byte Streams and Character Streams........4.37.2 Character Stream. 4-70
4.37.3 Difference between Byte and Character Stream. 4-70
4.38 Predefined Streams ... -70
4.39 Reading Console Input.... -71
4.40 Writing Console Output... 4-73
4.41 Print Writer Class...
4,42 FilelnputStream/FileOutputStream...
4.43 Console I/O using Scanner Class
4.43.1 Console Input...
4.43.2 Console Output.......
4.44 Multiple Choice Questions with Answers.
Chapter-5 Multithreading in Java 6 - 1) to © - 56)
Concurrency and Synchronization, Java Thread Model
5.1 Introduction to Thread .....scsssstesisiesent ses psn tices BED
5.2 Creating Thread....... 5-2
5.2.1 Extending Thread Class........ st sasensnasnsont ante isenseesssens sesssensaserssseesee = 3
5.2.2 Using Runnable Interface ......... 5-4
5.3 Thread Model......... 5-6
5.4 Thread Priorities .. 5-7
5.5 Synchronization Messaging .. 5-10
5.6 Creating Multiple Threads using Alive() and join() .....:sesesen 5-15
5.6.1 The isAlive() Method ss. Cote etetie eemaaseeet SAS:
5.6.2 The join() Method
Part I
Web Based Appli
5.7 Introduction to JavaScript...
5.7.1 Difference between Java and JavaScript...
(at)5.7.2 Features of JavaScript. 5-18
5.8 Using JavaScript in HTML...
5.9 Use of JavaScript for Creating Web Applications...
5.9.1 Input and Output... 5-22
5.9.2 Pop-Up Box 5-23
5.9.3 Function... 5-25
5.9.4 Form Design. 5-27
5.9.4.1 Text 4 5-27
5.9.4.2 Checkbox 5-29
5.9.4.3 Radio Button 5-30
5.9.4.4 BUttOM ren : 5-31
5.9.45 Select Element. 5-33
Part Il : Incroduc to JavaScript Framework
5.10 Angularss. 5+37
5.10.1 MVC Architecture tec : sesenen 5+ 38
5.10.2 Directives asses 5-38
5.11 ReactIS..... 5-43
5.11.1 Installation of REACUS. nse ‘ sidisidivhiuiantactaaial S44
5.11.2 Writing Simple Web Applications...... 5-47
5.12 Vues... 5-48
5.12.1 Installation Of VUEIS .asnnmenenesesesesen ilo srveneensnsee 5° A
5.12.2 Writing Web Application... 5-49
5.12.3 Basic Components of VuelS Script... 5-51
5.13 Multiple Choice Questions with Answer:
Unit - VI
Chapter-6 Logical and Functional Programming (6 - 1) to 6 - 32)
Part I : Functional Pro; g Paradigm
6.1 Introduction to Functional Programming...
(xiv)6.2 Understanding Symbol Manipulation.. tnsagen ganado 6-3
6.3 Basic LISP Functions.....
6.3.1 Building Blocks.
6.3.2 Lisp Manipulation Function
6.3.3 Mathematical Functions.
6.3.4 Eval Function ..
6.3.5 Basic Lisp Primitives.
6.4 Definitions, Predicates, Conditional and Scoping...
6.4.1 Definitions ............000+
6.4.2 Predicates 6-10
6.4.3 Conditional Statements ..emnennnsinninnnnnninnrenrenennnnnnnns 6° LL
6.4.4 Scoping ..... 206-13
6.5 Recursion and Iteration ..... 6-14
6.6 Properties, A- Lists,Arrays and Access FUNCtION. un 6-14
6.7 Using Lambda Definitions..... 6-16
6.8 Printing, Reading and Atom Manipulation 16-16
Part IN: Logic Programming Paradigm |
6.9 An overview of Prolog... 6-17
6.10 Syntax and Meaning of Prolog Programs... 16-19
6.10.1 Response to Query 6-22
6.11 Lists, Operators and Arithmetic. 6-27
6.12 List Structures... 6-28
6.13 Comparison between Functional Programming and Logical Programming
and Object Oriented Programming Languages Functional..... 1.6 +30
6.14 Multiple Choice Questions with Answers. 6-22
Solved Model Questions Papers
(M - 1) to (M- 4)NotesCoN)
Fundamentals of
Programming
Syllabus
Importance of Studying Programming Languages, History of Programming Languages, Impact of
Programming Paradigms, Role of Programming Languages, Programming Environments. Impact of
Machine Architectures: The operation of a computer, Virtual Computers and Binding Times
Programming paradigms - Introduction t0 programming paradigms, Introduction 0 four main
Programming paradigms- procedural, object oriented, functional, and logic and rule based.
Content:
1.1 Importance of Studying Programming Languages
1.2. History of Programming Languages
1.3. Role of Programming Languages
1.4. Programming Environments
1.5. Impact of Machine Architectures
1.6. Programming Paradigms. Dec.-17, Marks 6
1.7 Multiple Choice Questions
(1-7)Principles of Programming Languages 1-2 Fundamentals of Programming
El Importance of Studying Programming Languages
Following are the reasons for studying the programming language concepts -
1) Increased capacity to express ideas :
«The study of different programming languages makes the programmer with variety
of programming constructs.
* In this study, programmer can understand various data structures, control
structures abstractions and their ability.
‘Then they can use suitable programming constructs to express the ideas they want
to implement.
2) Improved background for choosing appropriate language :
* By the knowledge of various programming languages, one can be aware of its
variety of features.
* Hence while developing, a software application programmer can make appropriate
selection of the language whose features are most applicable.
* For example — if application requirement is use of GUI then the programmer will
choose Visual basic as a programming language
3) Increased ability to learn a new language :
* Due to the knowledge of programming constructs and implementation techniques,
programmer can learn new language easily
4) Better understanding of significance of implementation :
* By leaming and understanding different languages, programmer can know the
gn.
+ This knowledge leads to use the language more intelligently.
reasons behind the language de:
5) Better use of languages that are already known :
* By studying the concepts of programming languages, programmers can learn about
previously unknown and unused parts of the languages they already use and begin
touse those features
6) Overall advancement of computing :
* By understanding variety of features of programming languages such as arrays,
dynamic arrays, strings, dynamic memory allocation, generic programming - the
programmer can use these features for advance level implementation and
computing,Principles of Programming Languages 1-3 Fundamentals of Programming
eke eae!
[Explain the importance of studying programming language.
PA History of Programming Languages
4) Scientific applications
* The scientific applications require large numbers of floating point computations.
* Ittypically makes use of arrays.
+ The programming language used is - Fortran.
2) Business applications :
* The business applications are characterized by facilities of producing variety of
reports,
* Itrequires use of decimal numbers and characters data
* It also needs an ability to specify decimal arithmetic operations.
* The programming language preferred for building the business applications is -
COBOL,
3) Artificial intelligence
* The artificial intelligence is an area in which the computations are symbolic rather
than numer
. Symbolic computation means that symbols, consisting of names
rather than numbers
* 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 programming language used in this area of applications is - 1
4) Systems programming :
ystem programming is a system software which consists of collection of operating
tem and programming support tools.
* The system software is used continuously, hence it needs to be efficient
* It should also have a support for interfacing with external devices to be written.
(For example - some support programs for plug and play devices).
* The general programming languages such as C, C++ are usually preferred for
stem programming
LICATIONS® «An up thust for knowledgePrinciples of Programming Languages 1-4 Fundamentals of Programming
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 soon
* It need a support for variety of languages from markup languages (For example -
HTML), scripting(For example - PHP), to general-purpose(For example -Java),
E¥ Role of Programming Languages
EEESI Evolution of Major Programming Languages
FORTRAN |:
* It is designed for new IBM 704, which had index registers and floating point
hardware.
+ From this language onwards the idea of compilation came into existence.
* The first implemented version of Fortran has following features -
© Names could have up to six characters.
© Post-test counting loop such as DO was present.
© Ithas formatted 1/O
© Itallows user defined subprograms.
© There were no data typing statements
FORTRAN
© It was distributed in 1958
* Independent compilation was supported for FORTRAN II
FORTRAN WV,77,90 :
* Itis evolved during 1960-62
© Ithas explicit type declarations
* There was logical selection statement
* Subprogram names could be parameters
* It was standardized as FORTRAN 66 in 1966
* In FORTRAN 77 the character sting handling features was introduced. IF-THEN-
ELSE statement were introduced.
* Most significant changes took place in FORTRAN 90 by allowing use of modules,
dynamic arrays, pointers, recursion,CASE statements, parameter type checking,
TECHNICAL PUBLICATIONS® - An up thrust for knowledgePrinciples of Programming Languages 1-5 Fundamentals of Programming
Functional Programming : LISP :
* Itis a list processing language.
* This language is used in the research of Al.
The syntax is based on lambda calculus.
ALGOL 60:
+ Itsupports the block structure,
* Ithas two parameter passing methods.
It supports the subprogram recursi
n,
COBOL :
© The first macro facility in a high level language.
* Ithas a support for hierarchical data structures,
* Itcontains nested selection statements.
* Long names for variables up to 30 characters were allowed with hyphens.
# Ithas separate data division
BASIC :
© Itis easy to use and learn.
The current popular version of BASIC is visual basic.
PLA:
* It was designed by IBM and SHARE.
* Characterized by dynamic typing and dynamic storage allocation
* Variables are untyped i. A variable acquires a type when itis assigned a value
* Storage is allocated to a variable when itis assigned a value.
PASCAL :
* It is designed initially for teaching structured programming
+ It was small, simple and easy to learn.
© Itis developed in 1972 for system programming.
* Ithas powerful set of operators.
* Though designed as a systems language, it has been used in many application
areas.
TECHNICAL PUBLICATIONS® - An up thrust for knowledgePrinciples of Programming Languages 1-6 Fundamentals of Programming
PROLOG :
* Itis based on formal logic.
© Itis a Non-procedural language.
* Itis considered to be intelligent database system that uses an inferencing, process to
infer the truth of given queries.
* Itis comparatively inefficient.
ADA:
© For design of this language required huge design effort, involving hundreds of
people, much money, and about eight years.
+ By allowing use of packages, ADA has a support for data abstraction.
©. Itsupport the exception handling mechanism
* It allows the use of generic units and concurrency mechanism.
* It contains more flexible libraries.
CH:
* Itis developed as Bell labs in 1980.
It support for both procedural and object oriented features.
JAVA:
* Developed by Sun Microsystems in 1990.
* Itis based on C+
* Itsupports only OOP.
* Itcontains references but no pointers.
* Ithasa facility and support for applets and concurreney.
* Ithas libraries for applets, GUIs, database access.
© Itis widely used for web programming
Scripting Languages for WEB :
* Various scripting languages such as Perl, PHP, Python, JavaScript, Ruby and so on
are used as a scripting languages for web programming.
-NET Language : C#:
* Ibis based on C+, Java, and Delphi
* It includes pointers, delegates, properties, enumeration types, a limited kind of
dynamic typing, and anonymous types
«Is evolving rapidly.
TECHNICAL PUBLICATIONS® - An up that for knowledgePrinciples of Programming Languages 1-7 Fundamentals of Programming
Markup/Programming Hybrid Languages :
* XSLT: eXtensible Stylesheet Language Transformation (XSTL) transforms XML
documents for display
* Java Server Pages
collection of technologies to support dynamic Web documents.
Attributes of Good Language
Various attributes of good languages are -
1. Clarity, simplicity and unity
conceptual framework for thinking about the algorithm. It should provide the
The programming language should provide the
clear, simple and unified set of concepts that can be used as a primitives for
developing the algorithms. The language should allow to use different concepts
with the rules for their combinations with ease and simplicity. This attribute is
called conceptual integrity.
The syntax of the language should be such that readability of the program can be
increased
2. Orthogonality : In context of programming languages, a programming construct is
said to be orthogonal if these constructs can be freely used in combination with
each other. The orthogonality features expects that the meaning is context
independent. For instance - Pointer should be able to point to any type of variable
or data structure,
This feature makes the language easier to learn and programs are easier to write.
3. Naturalness for application : The syntax of a programming language should be
such that it should follow logical structure of the algorithm. Various algorithms
such as sequential algorithms, concurrent algorithms, logic algorithms and so on
have different natural structures which should be represented by the programming
languages. The language should provide appropriate data structures, operations,
and control structures for the problem to be solved
4. Abstraction : Abstraction means hiding the implementation details. This feature
allows the programmer to define and use the complicated structure in such a way
that the implementation details can be ignored. By this attribute - Programmer can
concentrate only on abstract properties without bothering, for their implementation
details. ADA and C++ are the languages that support for abstraction feature.
5. Program verification : The reliability of programs written in a language is always a
major issue. There are various techniques for program verification. One of the
techniques of program verification is to use test input data, In this technique, the
“AL PUBLICATIONS® - An up thrust for knowledgePrinciples of Programming Languages 1-8 Fundamentals of Programming
program is executed with test input data and the output is checked against the
specifications
If the semantic and syntactic structure is simple then the program verification
becomes simplified
6. Program environment : The programming environment includes well-documented
implementations, special editors and testing packages, version control services and
so on, The technical structure of programming language has a great influence on
use of programming environment appropriately.
7. Portability : Portability is a feature by which the program that work on one
platform can be modified to work on other platform.
8. Cost of use : The cost is major element in evaluation of any programming language.
The cost can be computed for various factors such as -
a) Cost of program execution : Cost of program execution is particularly important
for large production programs that will be executed repeatedly. The program
execution cost is greatly reduced due to use of optimizing compilers, efficient
register allocation, and design of efficient runtime support mechanism.
b) Cost of program translation : For compiling the large programs/systems, the
compilers take too much time. This increases the overall cost. In such a case, it is
important to have a fast and efficient compiler rather than a compiler that
produces optimized executable code.
©) Cost of program creation, testing and use : The cost is involved in program
designing, coding, t
ting and modifying. The Smalltalk and Perl are cost
effective languages in this aspect.
4) Cost of program maintenance : The maintenance cost can be four times more
than that of development cost. The cost of maintenance depend on various
characteristics of the language mainly it is dependent upon readability.
eke
1. Explain the Evolution of Maj
or Programming Lan;
ages
What are the attributes of Good language ?
£4 Programming Environments
Definition : Programming environment is an environment in which the programs can
be created and tested.Principles of Programming Languages 1-9 Fundamentals of Programming
Programming Environment consists of a collection of support tools that are used in
software development. Each support tool is basically one kind of program which is used
by the programmer during the stages of creation of program. These tools are editors,
debuggers, verifiers, data generators and so on.
EEERI Effect on Language Design
The programming environment influences on language design in two major areas
namely separate compilation and testing and debugging.
eparate Compilation Testing / Debugging
Separate compilation :
There are varying number of programmers working on design, code and test the parts
of programs. This require the language to be structured so that individual subprograms
or other parts can be separately compiled and executed without requirement of other
part. Later on these parts are to be merged into a final program.
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 are -
1. The statements such as extern can be used to indicate that particular data is used
from other subprogram.
Ny
Languages use scoping rules to hide names. One subprogram can be contained
within another subprogram so that the name of the outer subprograms are known
to separately compiled subprogram,
3. In object oriented programming, the feature like inheritance can be used to use the
shared data
Testing and Debugging :
Many languages contain some features that help in testing and debugging. For
example -
1. Breakpoint Feature : By this feature, the programmer can set the breakpoints in
the program. When the breakpoint is reached during the execution of the program,
the execution of the program is interrupted and control is given to the programmer.
The programmer can then inspect the program for testing and debugging
TECHNICAL PUBLICATION:
1 for knowledgePrinciples of Programming Languages 1-10 Fundamentals of Programming
2. Execution Trace Feature : By this feature particular variable or statement can be
tagged for tracing during the execution of the program
3. Assertions : The assertions is a conditional expression which is inserted as
separate statement in a program. For example following is a Java Code fragment in
which the assertion is used
System out print("Enter your age
int age = reader.nextint();
Assertion assert(age<18, "You are not allowed to vote"
EE@] Environment Framework
« Environment framework is nothing but the collection of infrastructure services that
can be used for program development purpose. These services are data repository,
Graphical user interface, security and communication services.
* Borland JBuilder is a programming environment that provides integrated compiler,
editor and debugger for Java development.
* The modern programming environment makes use of Visual Studio .NET for
4, Vist
developing the applications using
al Basic, NET, Jscript, J# and so on.
©) Unix is an old programming environment and has a strong, support for various
powerful tools for software production and maintenance. The UNIX GUI runs on
the top of basic UNIX kernel. Typical examples of such GUI are GNOME and KDE.
eck teeta
1. What is
language design
programming environment ? Explain the effect of programming environment on
2. Explain the concept of enviroment framework in programming environment
EEA impact of Machine Architectures
Operation of a Computer
Working of any computer is based on the software present in it. The software contains
collection of programs. These programs are created using suitable programming
language:
A computer consists of six major components that are associated with the
programming language:
. These components are —
4. Data
* Inany programming language there are variety of data items and data structures.
TECHN
LICATION:
‘An up thrust for knowledgePrinciples of Programming Languages 1-44 Fundamentals of Programming
The built in data types can be directly manipulated by hardware primitive
operations. Such built in data types are — integer, floating point numbers, double
precision floating point numbers, and strings
The data is stored and processed within data storage components of a computer.
The three major data storage components are —
© Main memory: Main memory consists of bil
subdivided into fixed length words
o High-speed Registers: The contents of registers represent either data or the
memory address of main memory containing data.
o External Files: The external files is generally stored on hard disk or on CD ROM.
It contains records.
External Files.
and
InpuyOurput
t
Main Memory
1
High Speed Registers
Fig. 1.5.1 Data storage components:
2. Primitive Operations
* A computer contains a set of built-in primitive operations such as addi
multiplication, subtraction and division.
The primitive operations are also used for controlling the sequence of execution of
programming statements.
3. Sequence Control
Computer must provide the mechanism for controlling the flow of execution of
programming instruction. This mechanism is called as sequence control.
Various primitive operations are used for sequence control. These operations
transfer the control flow from one memory location to another.
The next instruction to be executed is determined by the special purpose register
called program counter(PO).
The mechanism of execution of programming instruction is illustrated by following
figure.
TEC
"AL PUBLICATIONS® - An up thrust for knowledgePrinciples of Programming Languages 1-12 Fundamentals of Programming
Fetch Next Instruction
Decode Instruction
Fetch Designated Operands
Execute
Primitive Operations
Halt operation
No halt operation
Stop
Fig. 1.5.2 Steps for Program Execution
4, Data Access
Computer provides a controlling mechanism for supplying data for execution of
programming instruction. This mechanism is called data access.
5. Storage Management
6. Operat
* Computer provides the mechanism for controlling the storage for programs and
data resources.
© There are three types of storage components in computer and those are ~ (i) Main
Memory (ii) High speed Registers and (iii) External Files,
* Sometimes the speed of CPU and main memory does not get synchronized. Hence a
special memory called cache memory is used,
* Acache memory is high speed small memory situated in between the main memory
and CPU. The data present in the cache memory is immediately available CPU
1g Environment
+ Computer provides the mechanism by which external programs help in execution
of application or user programs which constitutes the programming environment
* The operating environment consists of peripheral storage and I/O devices.
TECHN
LICATION:
‘An up thrust for knowledgePrinciples of Programming Languages 213 Fundamentals of Programming
Translators and Virtual Architectures
© The pro
of translation of a program from high level programming language to
low level machine language is performed in following steps -
1. The program modules are separately translated into relocatable machine code.
This translator is called as compiler.
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.
Source
program
Compiler
Relocatable
machine code
Linker
Single relocatable
unit
Loader
Executable
unit
Inputdata—»} Interpreter. -—> Quiput data
(executed result)
Fig. 1.5.3 Language processing using translation
The modem 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.
Methods of Program Implementation
The three methods of language implementation are -
1) Compilation : This is a process in which the high level programs are translated into
machine languag
2) Pure interpretation : In this process, programs are interpreted line by line to target
program.
TECHNICAL PUBLICATIONS® « An up thrust for knowledgePrinciples of Programming Languages 1-14 Fundamentals of Programming
Input data ——» [ Interpreter
Result
Advantages :
1. Modification of user program can be easily made and implemented as execution
proceeds,
Type of object that denotes a variable may change dynamically.
3. Debugging a program and finding errors is simplified task for a program used
for interpretation.
4, The interpreter for the language makes it machine independent.
Disadvantages :
1, The execution of the program is slower.
2, Memory consumption is more.
3) Hybrid implementation system : In this system the programs are translated using
both interpreter and compiler
* Using compilers the high level programs are translated into intermediate language.
These intermediate languages are easy to interpret. The interpreter interprets the
intermediate language to form the machine code.
Examples - Perl is implemented using with hybrid implementation system. Initially
implementation of Java were all hybrid. The intermediate form of Java code is
called as byte code. This byte code provides the facility of execution of the code on
any platform. Thus portability to any machine(Platform independence) can be
achieved using byte code.
* The Just-In-Time (JIT) compiler is a component of the Java Runtime Environment
that improves the performance of Java applications at run time. Java programs
consists of classes, which contain platform neutral bytecode that can be interpreted
by a Java Virtual Machine(JVM) on many different computer architectures. At run
time, the JVM loads the class files, determines the semantics of each individual
bytecode, and performs the appropriate computation.
TECHNICAL PUBLICATIONS® - An up thrust for knowledgePrinciples of Programming Languages 1
15
Source Program
y
Fundamentals of Programming
Lexical analyzer
y
Syntax analyzer
1
Intermediate code
generator
:
input sta» (—)
’
Resulis
Fig. 1.5.4 Hybrid implementation system
Difference between Compiler and Interpreter
Sr. on
note interpreter
1. Demerit: The source program gets interpreted
every time it is to be executed, and every time
the source program is analyzed. Hence
interpretation is less efficient than Compiler.
2. The interpreters do not produce object code.
Merit; The interpreters can be made portal
because they do not produce object code
Merit: Interpreters are simpler and give us
improved debugging environment.
Compiler
Merit : In the process of compilation the
program is analyzed only once and then
the code is generated. Hence compiler is
efficient than interpreter.
‘The compilers produce object code.
Demerit : The compilers has to be present
on the host machine when particular
program needs to be compiled.
Demerit : The compiler is a complex
program and it requires large amount of
memory,
TECHNICAL PUBLICATIONS® - An up thrust for knowledgePrinciples of Programming Languages 1-16 Fundamentals of Programming
Concept of Preprocessor
* 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 -
o #include "mytestfile.h"
causes the preprocessor to copy the contents of mytestfilesh into the program at
the position of the #include.
o #define SIZE5
In the program we can declare an array of size 5 in following manner -
int a[SIZE];
EEEZ] Virtual Computers
Definition of Virtual Machine : Virtual machine is a piece of software which
simulates the actual machine environment. An implementation of programming,
language requires that the programs in the language are analysed and then
translated into a form that can be run by interpreter ie. on virtual machine first and
then on actual real machine.
* For a virtual machine environment the source program is translated into an
intermediary abstract form which is then interpretively executed.
* In this case, the source program first goes through three stages such as lexical
analyser, syntax analyser and type checker. Then the abstract syntax obtained from
these three phases is interpreted to get the translated output
* Due to this feature it is possible to execute the abstract code on any desired
platform,
* For example — Java virtual machine is a kind of virtual machine which plays an
important role in achieving the platform independence.
The general structure of virtual machine is as shown in Fig, 1.5.5.
TECHN
"AL PUL
LICATION:
‘An up thrust for knowledge