Вы находитесь на странице: 1из 21

NECN-CSE III B.

Tech I Sem (R15) 2019-20

NARAYANA ENGINEERING COLLEGE::NELLORE


Permanently affiliated to JNTUA, Ananthapuramu

(Accredited by NAAC with “A+” Grade)

BASIC CONCEPTS

Course: III B TECH - I SEM

Name Of the Sub: Principles of Programming Language Academic Year:2019-20


______________________________________________________________________

UNIT - I

SOFTWARE DEVELOPMENT PROCESS:


 Requirement analysis and specification
 Software design and specification.
 Implementation (coding).
 Verification and validation.
 Maintenance.

LANGUAGES AND SOFTWARE DEVELOPMENT ENVIRONMENT:


 software development environment we mean an integrated set of tools and
techniques that aids in the development of software.
 The environment is used in all phases of software development: requirements,
design, implementation, verification and validation and maintenance.
 It has processors, such as editors, compilers, simulators ,interpreters, linkers
debuggers,

LANGUAGES AND SOFTWARE DESIGN METHODS :

 GOALS OF SOFTWARE DESIGN:


The goals of software design include:
 Reliability
 Maintainability
 Efficiency

 LANGUAGE PARADIGMS:
The four main programming language paradigms are
 Procedural Programming Paradigm
 Functional Programming Paradigm
 Object-oriented Programming Paradigm
 Declarative Programming Paradigm

PROGRAMMING LANGUAGES:
A programming language is a set of commands, instructions, and other syntax use to
create a software program. Some of the general aspects of any programming language
include
 Declarations
NECN-CSE III B.Tech I Sem (R15) 2019-20

 Code blocks
 Assignments
 Conditionals
 Loops

 IMPERATIVE PROGRAMMING LANGUAGES:


The programming languages follow the following properties are called
imperative languages (or) Procedural programming languages.
 Sequential execution of instruction
 Use of variable representing memory locations
 Use of assignment to change the values of variables.
Examples of imperative programming languages are C,C++,Java etc.
 LOGIC PROGRAMMING LANGUAGES:
 The logic programming languages is based on symbolic logics.
 In logic programming languages a program consists of set of statements that
describe what is true about a desired result, as opposed to giving a particular
sequence of statements that must be executed in a fixed order to produce the
result.

ORTHOGONALITY:
Orthogonality is a system design property facilitating feasibility and compactness of
complex designs. Orthogonality guarantees that modifying the technical effect produced
by a component of a system neither creates nor propagates side effects to other components
of the system. A langauge is said to be orthogonal if it allows the programmer to mix
language constructs freely.

SYNTAX AND SEMANTICS:


 Syntax is a set of rules that specify the composition of programs from letters,
digits, and other characters. They define form of the language.
Ex: datatype variable_name1, variable_name2,……….; is the syntax of a
declaration statement in C language.
 Semantics rules specify “the meaning” of any syntactically valid program
written in some programming language.
Ex: int vector [10];
 The semantics of above statement in C is that to reserve space for 10 integer
elements for a variable named ‘vector’.

 EBNF:
EBNF is a context free grammar used to define the syntax of programming
languages.The most common extensions are

 Option
In EBNF, square brackets around an expansion, [ expansion ], indicates that
this expansion is optional.
For example, the rule:
<term> ::= [ "-" ] <factor>
allows factors to be negated.
NECN-CSE III B.Tech I Sem (R15) 2019-20

 Repetition
In EBNF, curly braces indicate that the expression may be repeated zero or
more times.
For example, the rule:
<args> ::= <arg> { "," <arg> }
defines a conventional comma-separated argument list.

 Grouping
To indicate precedence, EBNF grammars may use parentheses, (), to explictly
define the order of expansion.
For example, the rule:
<expr> ::= <term> ("+" | "-") <expr>
defines an expression form that allows both addition and subtraction.

 Operational semantics:
 At the highest level, the interest is in final result of the execution of a
complete program, this is called the natural operational semantics.
 At the lowest level, operational semantics can be used to determine the
precise meaning of a program through an examination of the complete
sequence of state changes that occur when the program is executed; this is
called structural operational semantics.

LINKER & LOADER:


 LINKER
Linker is a device, which will provides communication in between object files
and header files.
 LOADER
Loader is a device, which is used to load executable file into main memory .

COMPILER AND INTERPRETER:

Compiler Interpreter
Compiler is translating device Interpreter is translating device
Compiler can convert entire Interpreter can convert program in the form of
program at a time line-by-line
Compiler can execute program very Interpreters are slower than compilers
quickly
If any errors occur in program we If any errors occur in program no need to
have to compile total program again compile total program again
Example : C,C++, Ada compilers Examples : LISP,Java.

BINDING:
A Program composed of entities, such as variables, routines, and statements. Program
entities have certain properties is called attributes. The values of attribute must set before
they can be used. Setting the value of an attributes is called as binding.
Examples of binding include:
 Language definition time binding
 Language implementation time binding
NECN-CSE III B.Tech I Sem (R15) 2019-20

 Compile time binding


 Runtime binding.

VARIABLE:
TUPLES OF A VARIABLE:
A variable contains five tuples, such as
 name
 scope
 type
 l-value
 r-value
L- VALUE AND R-VALUE:
 l_value is the memory location associated with the variable
 r_value is the encoded value stored in the variable’s location

STATIC SCOPE BINDING AND DYNAMIC SCOPE BINDING:


Variables can be bound to a scope either static or dynamic

 STATIC SCOPE BINDING:


 Static scope binding is also called as lexical scoping, it defines the scope in
terms of the lexical structure of a program, that is each reference to a
variable can be statically bound to a particular variable declaration by
examining the program text without executing it.
 Static scope binding rules are adopted by most programming languages
such as C.
 DYNAMIC SCOPE BINDING:
Dynamic scope binding define the scope of a variable’s in terms of program
execution. Dynamic scope binding rules are adopted by most programming
languages such as APL, LISP, SNOBOL4.

ROUTINE:
A routine is a portion of code within a larger program that performs a specific task
and is relatively independent of the remaining code. Like variables, routines have a name,
scope, type, l_value, and r_value.

 GENERIC UNIT:
A generic unit is a program unit that is either a generic subprogram or a
generic package. A generic unit is a template, which can be parameterized,
and from which corresponding (nongeneric) subprograms or packages can be
obtained. The resulting program units are said to be instances of the original
generic unit.

 ALIASING:
In computer programming, aliasing refers to the situation where the same
memory location can be accessed using different names. For instance, if a
function takes two pointers A and B which have the same value, then the name
A aliases the name B.
NECN-CSE III B.Tech I Sem (R15) 2019-20

 DATA PARAMETER:
The data parameters are:
 call by reference,
 call by copy, and
 call by name

 ROUTINE PARAMETERS
Some languages treat routines as first class objects and support passing them
as parameters to other routines. Such parameters are called as routine
parameters Routine parameters behave differently in statically and
dynamically scoped languages.

RUN(EXECUTION)TIME STRUCTURE
In this section we discuss how the execution-time processing of programming
languages may be explained using SIMPLESEM Languages are differed from C1 to C5 by
using Static languages, Stack-based languages and fully Dynamic languages
 C1: A language with only simple statements
 C2: Adding simple routines
 C3: Supporting recursive functions
 C4: Supporting block structure
 C5: Towards more dynamic behaviors
NECN-CSE III B.Tech I Sem (R15) 2019-20

UNIT - II
BUILT-IN TYPES OF A PROGRAMMING LANGUAGE:
The built-in types of a programming language reflect the different views provided by
typical hardware.
Examples of built-in types are:
 booleans, i.e., truth values TRUE and FALSE, along with the set of
operations defined by Boolean algebra
 characters, e.g., the set of ASCII characters
 integers, e.g., the set of 16-bit values in the range <-32768, 37767>
 reals, e.g., floating point numbers with given size and precision

DATA AGGREGATES AND TYPE CONSTRUCTORS:


 Programming languages allow aggregations of elementary data objects
and, recursively, aggregations of aggregates by providing a number of
constructors. The resulting objects are called compound objects.
 A well-known example is the array constructor, which constructs
aggregates of homogeneous-type elements.
 Any no. of instances can be defined for such compound types and these
compound types are called as type constructors.

CARTESIAN PRODUCT:
 The Cartesian product of n sets A1, A2, . . ., An, denoted A1 x A2 x . . . x
An, is a set whose elements are ordered n-tuples (a1, a2, . . ., an), where
each ak belongs to Ak.
 Examples of Cartesian product constructors in programming languages are
structures in C, C++, Algol 68 and PL/I, records in COBOL, Pascal, and
Ada.
 COBOL was the first language to introduce Cartesian products, which
proved to be very useful in data processing applications.

FINITE MAPPING:
 A finite mapping is a function from a finite set of values of a domain type
DT onto values of a range type RT. Programming languages provide the
array construct to define finite mapping as data aggregates.
 The index range of the array is the domain of the mapping and values
stored in the array is range of the mapping.
 For example in C, the following declaration,
char ch[5]= {‘n’,’e’,’c’,’g’,’\0’};
defines a mapping from integers in the domain 0 to 4 onto the set of characters
{‘n’,’e’,’c’,’g’,’\0’}.

DISCRIMINATED UNIONS DIFFER FROM UNIONS:


Discriminated unions differ from unions in that elements of a discriminated union are
tagged to indicate which set the value was chosen from. Given an element e belonging to the
discriminated union of two sets S and T, a function tag applied to e gives either ’S’ or ’T’.
Element e can therefore be manipulated according to the value returned by tag.
NECN-CSE III B.Tech I Sem (R15) 2019-20

POWER SET:
A variable values can be any subset of a set of elements of a given type T and the type
of such variables is called as power set (T), the set of all subsets of elements of type T. Type
T is called the base type.
For example, suppose that a language processor accepts the following set O of options
 LIST_S, to produce a listing of the source program;
 LIST_O, to produce a listing of the object program;
 OPTIMIZE, to optimize the object code;
 SAVE_S, to save the source program in a file;
 SAVE_O, to save the object program in a file;
 EXEC, to execute the object code.
A command to the processor can be any subset of O, such as
{LIST_S, LIST_O}
{LIST_S, EXEC}
{OPTIMIZE, SAVE_O, EXEC}
That is, the type of a command is powerset (O).

SEQUENCE:
A sequence consists of any number of occurrences of elements of a certain
component type CT. Sequences are used to represent objects of unknown size such as
sequential files.

TYPES OF RECURSION:
A Recursive data type T can be defined as a structure that contains components of
same type T. Recursion is better explained by the concept of functions.
The two types of recursion are
 Direct recursion: A function is directly recursive if it contains an explicit
call to itself.
 Indirect recursion: A function is indirectly recursive if it calls to another
function which ultimately calls the function itself.

CONSTRUCTOR:
 A mechanism provided in object oriented programming languages to
initialize the objects when it is being created is known as constructor.
 A constructor operation has the same name as the class name and is
invoked automatically when a variable of class type is allocated.
 In general, there may be two types of constructors namely, Normal
Constructor and Copy Constructor.

LANGUAGE ERRORS AND APPLICATION ERRORS:


Errors can be classified in two categories: language errors and application errors.
 Language errors are syntactic and semantic errors in the use of the
programming language.
 Application errors are deviations of the program behavior with respect to
specifications.
NECN-CSE III B.Tech I Sem (R15) 2019-20

STATIC AND DYNAMIC TYPE CHECKING:


The two primary methods of type checking are static type checking and dynamic type
checking.

Static Type Checking Dynamic Type Checking


1. It occurs before execution of a 1. It occurs during the execution of the program.
program.
2. It results in optimized machine 2. It results in less optimized code.
code.
3. It eliminated the need of repeated 3. It included the possibility of run time errors,
checking, every time the program is and hence need run time checks for every
executed. execution of the program.
4. It may not cover language errors 4. It supports type failures at run time through
that occur at run time such as divide some mechanisms such as error handling.
by zero.
5. It compromises with the power of 5. It supports powerful features such as dynamic
the language. dispatch, late binding etc.

TYPE COMPATIBILITY TYPES:


Type compatibility is also sometimes called conformance or equivalence. Type
checking procedure can verify that all operations are always invoked correctly, i.e., the types
of the operands are compatible with the types expected by the operation.
There are two types of type compatibility types such as
 Name Compatibility: The strict conformance rule where a type name is
only compatible with itself is called Name Compatibility.
 Structural compatibility: Two types T1 and T2 are structurally compatible
if
 T1 is name compatible with T2 (or)
 T1 and T2 are defined by applying the same type constructor and have
the same structure.

TYPE CONVERSION:
In computer science, type conversion (coercion) and typecasting refers to changing an
entity of one datatype into another.
The basic difference between type conversion and type casting is-- type conversion is done
“automatically” by compiler whereas, type casting is to be “explicitly done” by the
programmer.
Type casting Type conversion
One data type is assigned to another by the Conversion of one data type to another
user, using a cast operator then it is called automatically by the compiler is called "Type
"Type Casting".can also be applied to two Conversion".
Type casting Type conversion can only be implemented
'incompatible' data types. when two data types are 'compatible'.
For casting a data type to another, a casting No operator required.
operator '()' is required.
Destination type can be smaller than source Here the destination type must be larger than
type.
It is done explicitly during program source type.
It is done implicitly while compiling.
designing. conversion.
Narrowing Widening conversion.
NECN-CSE III B.Tech I Sem (R15) 2019-20

TYPES AND SUBTYPES:


 A Type is defined as a set of values with an associated set of operations.
 A type S is a subtype of a type T if an expression of type S can be
used in any context that expects an element of type T.
For example, in Ada language type and subtypes are defined as follows.
type Int_Vector is array (Integer range < >) of Integer;
subtype Vec_100 is Int_Vector (0. .99); --this subtype constrains the bounds of the array
to 0. .99
subtype SMALL is Integer range -9. .9; --this subtype defines a small set of integers

DECLARATION LIST OF ELEMENTS IN C AND ADA:


 In C-language list of elements can be declare as:
struct int_list {
int val;
int_list* next;
};
int_list* head;

 In Ada language list of elements can be declare as :


type INT_LIST_NODE;
type INT_LIST_REF is access INT_LIST_NODE;
type INT_LIST_NODE is
record
VAL: INTEGER;
NEXT: INT_LIST_REF;
end;
HEAD: INT_LIST_REF;

ENUMERATION TYPES IN PASCAL AND ADA:


In most of the programming languages it is possible to create new primitive types
such as enumeration type in Pascal, C and Ada.
An enumeration example is shown below:

 IN PASCAL
type color = (white, yellow, red, green, blue, black);

 IN ADA
type color is (white, yellow, red, green, blue, black);

 SIMILARLY, IN C
enum color {white, yellow, red, green, blue, black};

POINTERS AND GARBAGE COLLECTION:


A pointer holds as a value the address of an object of the type to which the pointer is
bound to. Pointers usually can have a special null value (e.g., void in C and C++, nil in
Pascal). Such a null value can be represented by an address value that would cause a
hardware-generated error trap to catch an inadvertent reference via a pointer with null val
The memory allocated to hold a heap object can be released for later reuse if the
object is no longer accessible. Such an object is said to be garbage.
NECN-CSE III B.Tech I Sem (R15) 2019-20

There are two main aspects involved in heap management. One is the recognition that some
portion of allocated memory is garbage; the other is to recycle such memory for new memory
allocation requests issued by the user and this process is called garbage collection.

ATTRIBUTE GRAMMAR:
An attribute grammar links syntax with semantics.
 Every grammar production has a semantic rule with actions (e.g.
assignments) to modify values of attributes of (non)terminals
 A (non)terminal may have a number of attributes
 Attributes have values that hold semantic information about the
(non)terminal
 General form:
Production Semantic rule
<A> -> <B> <C> A.a := ...; B.a := ...; C.a := ...
A.a denotes attribute a of nonterminal <A>
 Semantic rules are used by a compiler to enforce static semantics and/or to
produce an abstract syntax tree while parsing token stream
 Can also be used to build simple language interpreters.
NECN-CSE III B.Tech I Sem (R15) 2019-20

UNIT - III
EXPRESSIONS:
Expressions define how a value can be obtained by combining other values through
operators. The values from which expresions are evaluated are either denoted by a literal, as
in the case of the real value 57.73, or they are the r_value of a variable.

UNARY AND BINARY OPERATORS:


 A unary operator is applied to only one operand.
 A binary operator is applied to two operands.
 In general, a n-ary operator is applied to n operands.
For example, ’-’ can be used as a unary operator to transform–say–the value of a positive
expression into a negative value. In general, however, it is used as a binary operator to
subtract the value of one expression from the value of another expression.

OPERATOR NOTATIONS:
Operator’s notation are infix, prefix, and postfix. Infix notation is the most common
notation for binary operators: the operator is written between its two operands, as in x + y.
Postfix and prefix notations are common especially for non-binary operators.

PREFIX NOTATION AND POSTFIX NOTATION:


In prefix notation, the operator appears first, and then the operands follow. This is the
conventional form of function invocation, where the function name denotes the operator.
For example, form as * a + b c
In postfix notation the operands are followed by the corresponding operator. Assuming that
the arity of each operator is fixed and known, expressions in prefix and postfix forms may be
written without resorting to parentheses to specify subexpressions that are to be evaluated
first.
For example, postfix form as a b c + *

IF STATEMENT IN ALGOL 60:


Two forms are possible in if statement in ALGOL 60, as shown by the following examples:

if i=0 if i=0
then i:=j; then i:=j;
else begin i:=i+1;
j:=j-1;
end;
In the first case, no alternative is specified for the case i ¦ 0, and thus nothing happens if i ¦ 0.
In the latter, two alternatives are present. Since the case where i ¦ 0 is described by a
sequence, it must be made into a compound statement by bracketing it between begin and
end.

MULTIPLE-CHOICE SELECTION IN C++:


C++ provides the switch construct, illustrated by the following fragment:
Switch (operator){
case ‘+’:
result=operand1+operand2;
break;
case ‘*’
result=operand1*operand2;
NECN-CSE III B.Tech I Sem (R15) 2019-20

break;
case ‘-’:
result=operand1-operand2;
break;
case ‘/’:
result=operand1/operand2;
break;
default :
break; do nothing
};

ROUTINES:
Routines are a program decomposition mechanism which allows programs to be
broken into several units. Routine calls are control structures that govern the flow of control
among program units.
The relationships among routines defined by calls are asymmetric: the caller transfers
control to the callee by naming it explicitly. The callee transfers control back to the caller
without naming it.

DIFFERENT KINDS OF ROUTINES IN LANGUAGES:


The languages distinguish between two kinds of routines: procedures and functions.
 A procedure does not return a value: it is an abstract command which is
called to cause some desired state change. The state may change because
the value of some parameters transmitted to the procedure gets modified,
or because some nonlocal variables are updated by the procedure, or
because some actions are performed on the external environment (e.g.,
reading or writing).
 A function corresponds to its mathematical counterpart: its activation is
supposed to return a value, which depends on the value of the transmitted
parameters.

EXCEPTION HANDLING IN ADA:


Ada provides a set of four predefined exceptions that can be automatically trapped
and raised by the underlying run-time machine:
 Constraint_Error: failure of a run-time check on a constraint, such as
array index out of bounds, zero right operand of a division, etc.;
 Program_Error: failure of a run-time check on a language rule. For
example,a function is required to complete normally by executing a return
statement which transmits a result back to the caller. If this does not
happen, the exception is raised;
 Storage_Error: failure of a run-time check on memory avaliability; for
example, it may be raised by invocation of new;
 Tasking_Error: failure of a run-time check on the task system;

Exception handling in C++:


Exceptions may be generated by the run-time environment (e.g., due to a division by
zero) or may be explicitly raised by the program.
An exception is raised by a throw instruction, which transfers an object to the corresponding
handler.
NECN-CSE III B.Tech I Sem (R15) 2019-20

A handler may be attached to any piece of code (a block) which needs to be fault tolerant. To
do so, the block must be prefixed by the keyword try.

PATTERN MATCHING:
Pattern matching is a high level way of stating conditions, based on which, different actions
are specified to occur. Pattern matching is the most important control structure of the string
manipulation programming language SNOBOL4.
Pattern matching is also provided by most modern functional programming languages, like
ML, Miranda, SASL, and is also provided by the logical language PROLOG and by rule-
based systems.

STATE DIAGRAM FOR A PROCESS:


States of process:
The states of process are
 Waiting
 Ready
 Running

GOALS OF SOFTWARE DESIGN:


The goals of software design include:
 Reliability
 Maintainability
 Efficiency

ENCAPSULATION IN PROGRAMMING:
A program unit provides a service that may be used by other parts of the program,
called the clients of the service. The unit is said to encapsulate the service.

INFORMATION HIDING:
Information hiding is a design method that emphasizes the importance of concealing
information as the basis for modularization. Encapsulation mechanisms are linguistic
constructs that support the implementation of information hiding modules.
SKETCH OF THE PRODUCER AND CONSUMER TASKS IN ADA:

PRODUCER CONSUMER
loop loop
produce a new value V; Buffer_Handler.RTemove(V);
Buffer_Handler.RTemove(V); consume V;
exit when V denotes the end of exit when V denotes the end of
the stream; the stream;
end loop end loop
NECN-CSE III B.Tech I Sem (R15) 2019-20

STRUCTURE OF THE PASCAL PROGRAM:


A Pascal program has the following structure.
program program_name (files);
declarations of constants, types, variables, procedures and
functions;
begin
statements (no declarations)
end.

SEMAPHORES:
A semaphore is a data object that can assume an integer value and can be operated
on by the primitives P and V.
The semaphore is initialized to a certain integer value when it is declared
NECN-CSE III B.Tech I Sem (R15) 2019-20

UNIT - IV

OBJECT-ORIENTED PROGRAMMING:
The programs consist of procedures and data structures, objects are entities that
encapsulate data and related operations is called Object-Oriented program.

CHARACTERISTICS OF OBJECT-ORIENTED PROGRAMMING LANGUAGES:


Object-oriented programming languages are characterized by their support of four
facilities:
 Abstract data type definitions,
 Inheritance,
 Inclusion polymorphism, and
 Dynamic binding of function calls.

FEATURES OF OBJECT ORIENTED LANGUAGES:


The important features of object oriented programming languages are:
 Encapsulation or data abstraction
 Inheritance
 Polymorphism or Dynamic Binding

SINGLE AND MULTIPLE INHERITANCES:

SINGLE INHERITANCE MULTIPLE INHERITANCE

Derived class inherits a single base class. Derived class inherits two or more than two
base class.

Derived class access the features of single Derived class access the combined features of
base class inherited base classes

Require small amount of run time over head Require additional runtime overhead as
compared to single inheritance

OBJECT:
The pure terminology of object-oriented languages refers to objects that are instances
of classes. An object contains a number of instance variables and supports a number of
methods.
NECN-CSE III B.Tech I Sem (R15) 2019-20

INHERITANCE:
Inheritance is a linguistic mechanism that allows us to do just that by defining a new
class which “inherits” the properties of a parent class.

STACK OPERATIONS IN OBJECT-ORIENTED AND PROCEDURE LANGUAGES:


Given a stack data structure s, in a procedural language we would call a push
operation to add an element as in:
push (s, x);
Dealing with objects, as we have seen in C++, we tell the stack object to push an
element onto itself, as in:
s.push(x);

CONSTRUCTOR AND DESTRUCTOR:


 A constructor has the same name as the class. Constructors cannot be
virtual. Constructors must be declared in public. Constructors have
arguments.
 A destructor is invoked automatically when the object is destroyed-
either explicitly through a call to delete or implicitly when the object
goes out of scope. Destructors can be Virtual. Destructors must be
declared in public. Destructors have no arguments.

VIRTUAL FUNCTION:
Virtual functions may be used to define abstract classes. For example, we may specify
that a shape must have three functions named draw, move, and hide, without providing an
implementation for these functions.

PURE VIRTUAL FUNCTION:


A virtual function that does not have an implementation is called a pure virtual
function.
For example, In C++, we can declare virtual function using keyword virtual as in:
virtual return type function name ()=0;
To write a pure virtual function, its body is written as = 0;.

ROLE OF PROTECTED ACCESS SPECIFIER:


Protected entities are visible within the class and any derived subclasses.

VIRTUAL MACHINE:
Virtual machines acts as run time engine to run a particular programming language
applications. Examples of virtual machines are
 JVM (Java Virtual Machine) acts as runtime engine to run Java
applications
 PVM (Parrot Virtual Machine) acts as runtime engine to run Perl
applications.
 CLR (Common Language Runtime) acts as runtime engine to run .NET
based applications.

TAGGED TYPE:
A record type or private type that has the reserved word tagged in its declaration is
called a tagged type.
NECN-CSE III B.Tech I Sem (R15) 2019-20

TYPE EXTENSION:
When deriving from a tagged type, additional components may be defined. As for any
derived type, additional primitive subprograms may be defined, and inherited primitive
subprograms may be overridden. The derived type is called an extension of the ancestor type,
or simply a type extension.

LANGUAGES SUPPORT OBJECT-ORIENTED PROGRAMMING FEATURES:


The following languages support object-oriented programming:
 C++
 Ada 95
 Eiffel
 Smalltalk

DISPATCHING OPERATIONS:
The primitive subprograms of a tagged type, the subprograms declared
by formal_abstract_subprogram_declarations, and the stream attributes of a specific tagged
type that are available at the end of the declaration list where the type is declared are
called dispatching operations.

DYNAMIC BINDING:
The functions are bound to the code to be executed at compile time. is known as early
binding and if so happened at run time then is called late binding or dynamic binding.

USE OF INHERITANCE HIERARCHY:


Hierarchical organization is an effective method of controlling complexity. The
inheritance relationship imposes a hierarchy and provides a mechanism for the development
of a hierarchically organized families of classes.

ABSTRACT DATA TYPE DEFINITION IN ADA 95:


package Planar_Objects is
begin
type Planar_Object is abstract tagged null record;
function Distance (O: Planar_Object'Class) return Float is abstract;
procedure Move (O: inout Planar_Object'Class; X, Y: Float) is abstract;
procedure Draw (O: Planar_Object'Class) is abstract;
end Objects;
NECN-CSE III B.Tech I Sem (R15) 2019-20

UNIT - V

CHARACTERISTICS OF IMPERATIVE LANGUAGES:


Any imperative programming language contains the following charcterstics:
 Sequence of statements
 Order of execution of statements is important
 Programs contain state and can change state
 Programs use mutable data
 Programs may have side-effects
 Program use repetitions

FUNCTION IN MATHEMATICAL AND PROGRAMMING:


A function is a rule for mapping (or associating) members of one set (the domain set)
to those of another (the range set).

 COMPONENTS OF FUNCTIONAL PROGRAMMING:


A functional programming language has three primary components:
 set of data objects.
 set of built-in functions.
 set of functional forms (also called high-order functions) for building
new functions
 EXAMPLES OF FUNCTIONAL PROGRAMMING
 ML
 CLOS

SUBSTITUTION:
Substitution is used to replace all occurrences of an identifier with an expression

EXPRESSIONS IN LAMBDA CALCULUS


Lambda expressions represent values in the lambda calculus. There are three kinds of
expressions:
 An expression may be a single identifier such as x.
 An expression may be a function definition.
 An expression may be a function application

ML:

 FUNCTIONS IN ML:

In ML, we can define a function without giving it a name just as a lambda expression.
For example, as we have seen:
fn(x, y):int => x*y
is a value that is a function that multiplies its two arguments.

 LIST STRUCTURE IN ML:

The list is the major data structuring mechanism of ML; it is used to build a finite
sequence of values of the same type.
NECN-CSE III B.Tech I Sem (R15) 2019-20

Square brackets are used to build lists: [2, 3, 4], ["a", "b", "c"], [true, false].
The empty list is shown as [] or nil.
A list has a recursive structure: it is either nil or it consists of an element followed by
another list.
The first element of a nonempty list is known as its head and the rest is known as its tail.

 LIST OPERATORS IN ML:


 There are many built-in list operators.
 The two operators hd and tl return the head and tail of a list,
respectively.
So: hd([1,2,3]) is 1 and tl([1,2,3]) is [2,3].
hd and tl are polymorphic.
The construction operator :: takes a value and a list of the same type of
values and returns a new list: 1::[2,3] returns [1,2,3].
We can combine two lists by concatenation: [1,2]@[3] is [1,2,3].

 BUILT-IN TYPE CONSTRUCTORS IN ML:


There are several built-in type constructors:
 lists
 records
 tuples, and
 functions.
 STACK MODULE IN ML:

The example of stack module is


begin
structure Stack = struct
exception Empty;
val create = [];
fun push(x, stack xs) = stack (x::xs);
fun pop (stack nil) = raise Empty;
| pop (stack [e]) = []
| pop (stack [x::xs]) = stack [xs];
fun top(stack nil) = raise Empty;
| top(stack [x::xs]) = x;
fun lenght(stack []) = 0
length (stack [x::xs]) = length (stack [xs]) + 1;
end;
LISP:
 AATOM IN LISP:

An atom is a string of characters (letters, digits, and others).


The following are atoms:
 A
 AUSTRIA
 68000
 LIST IN LISP:

A list is a sequence of atoms or lists, separated by space and bracketed by


parentheses.
NECN-CSE III B.Tech I Sem (R15) 2019-20

The following are lists:


(FOOD VEGETABLES DRINKS)
((MEAT CHICKEN) (BROCCOLI POTATOES TOMATOES) WATER)
(UNC TRW SYNAPSE RIDGE HP TUV)
The empty list “()”, also called NIL.
The truth value false is represented as () and true as T.
 QUOTE IN LISP:

QUOTE is the identity function. It returns its (single) argument as its value.
Examples
 (QUOTE A) = 'A = A
 (QUOTE (A B C)) = '(A B C) = (A B C)
PROLOG:

 TERM IN PROLOG:

The basic syntactic constituent of a PROLOG program is a term. A term is a constant,


a variable, or a compound term. A compound term is written as a functor symbol
followed by one or more arguments, which are themselves terms.
A ground term is a term that does not contain variables. Constants are written as
lower-case letter strings, representing atomic objects, or strings of digits (representing
numbers). Variables are written as strings starting with an upper-case letter.

 CLAUSES IN PROLOG:

PROLOG programs are written as a sequence of clauses.


A clause is expressed as either a single predicate, called fact, or as a rule of the form
conclusion :- condition
where :- stands for "if", conclusion is a single predicate, and condition is a
conjunction of predicates.

 UNIFIER IN PROLOG:

Two terms are said to unify if a substitution can be found that makes the two terms
equal. Such a substitution is called a unifier. For example, the substitution
s1 = {<X, a>, <Y, b>, <Z, b>} is a unifier for the terms f (X, Y) and f (a, Z).

 RULE-BASED LANGUAGES:

Rule-based languages are common tools for developing expert systems. An expert
system is a program that behaves like an expert in some restricted application domain.
Such a program is usually structured as a knowledge base (KB), which comprises the
knowledge that is specific to the application domain, and an inference engine.

DIFFERENCE BETWEEN LOGIC AND RULE BASED LANGUAGES:


The main difference between logic and rule-based languages is that, Logic languages
are firmly based on the formal foundations of mathematical logic, rule-based languages are
not.
NECN-CSE III B.Tech I Sem (R15) 2019-20

EXISTENTIAL QUERY:

In PROLOG an existential query is one that contains variables. For example,


?-sort([3,2,7],X)
is an existential query which means “is there an X such that sort([2,3,7]) gives X?”.
Existential queries can be accommodated in the deduction process using a rule called
Existential rule.

Вам также может понравиться