Академический Документы
Профессиональный Документы
Культура Документы
BASIC CONCEPTS
UNIT - I
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
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.
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.
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
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
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
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’}.
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.
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
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};
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
UNIT - V
SUBSTITUTION:
Substitution is used to replace all occurrences of an identifier with an expression
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.
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.
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:
CLAUSES IN PROLOG:
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.
EXISTENTIAL QUERY: