PPL Unit 1 and 2 Decode Scan
PPL Unit 1 and 2 Decode Scan
stng
loop
Control
Veriebles
Inslde
the for
Labeled
Continue).
String
Handine
String
and
Loop Breab
Programming Language
iabeted
using Java
Stetements
1
E n c a p s u l a t i o n
methods
astia
gning Syntax and Semantics
Polymorphism,
I n h e r t a n c e ,
declaring
objects
V constris.
UNIT
fundementals.
returning
& ralue. ructon
MethodsCles
class. methode
to t
Cesses end Puh
methods orerloeding
addtng
rertables
finalire0
method.
control.
static. final. nested
final
objects
kerrord
gerhage returning
rarieble-length
arguments
Language and Software Development Environments
obiect as
perameter.
erquments. Using super. multu
1.1:
pesting ine references.
commend
clas de
tmner
clesses super dynamic method
ftware development process.
tnheritence.
orerriding.
and method
package term software
Defining a Definethe
acoess
Member
end (defn 1
combination of
c o n s t r u c t o r
interfaces
hiererchy
ining is a sequential
Software development process
Pacbages packages,
Obiect cles
ebrtract
ciesses
access
protection.
Importng
intertaces, ding inte
extending inter
nterface and at
CLASSPATH in Ans.
well defined starting and ending points
each having
end rariebles
pecheges
nesting
appiring). phases, each
tmpiementetior
cleuses nested ty
statements.
Streams. byte Streams and Ans.
multiple catch Vo:
own exception
sub ciasses). Managing console input. Writng Console Requirement
Verification
and validation
Testing
Maintenance
this phase.
a document
which is
then documented in
nese requirements are Specification (SRS).
popularly known as Software Requirement
1-2 Pyog Lenguage Smtar and Se
PPL
Specification 1-3 Prgramntng Lamgusge Synter end Semania
(2 Sofhware Design and
and specificati 1.2 Language and Software Destgn Methods
The SRS is used during the software design ation
During this phase. various software modules
and their interfa
Important Points to Remember
designed The programming languages have some programming constructs
3) Implementation using which particular software design method canbe
impiementation is a phase in which the coding i5 done in suitah implemented easily.
language with the help of design document. Some languages can be
programming implemented with the heip of objects.
Idealy it shoukd be simply mapping of software design intot Such languages are called object oriented
programming
coresponding code. language. For example -C, Java
4 Verification and Validation Similary Pascal or C are structured programming languages.
03 What do you mean by programming paradigm?
This phase is for checking the quality of the software system being Ans.: The programming paradigm represents a specific programming
deveioped style suitable for implement specific software design methodd
Verificeion means "Are we
building the product right?" and Q4 Explain the styles ofsoftware design.
validaion mezns "Are we building the
right product". Ans.
(5) Testing Procedurai programming
Decaratve programming
Fig Q.4.1 Styles of software design
nd Se.
Programming Language Syntax and Seman
1-4
Semantics
1-5 Programmng Language Syntax and
PPL
Programming
1he focus of this stv PPL
1)Procedural and functions.
1.3 Languages and Computer Architecture
is on procedures
programming language
This programming style is mainly
ma.
Programming:
(2)Functional functions. The expressions.
and ns Important Points to Remember
applicable for of mathematical
use
architecture in computer is
blocks of this programmin The most commonly used computer
building
functions are the primary
Haskell, ML are
the examples similar to Von Neumann architecture.
Programming languages like of CPU, Memory Unit,
The Von Neumann architecture consists
functional programming
When the abstract data type Input deviceand Output device.
(3)Abstract Data Type Programming: then this style is used. CLU Q.5 Explain with diagram
the relationship between languages
and
variables, functions, procedures and so on. These modules can be Programming languages
primarily used to export the services from one module to another.
Modula-2 and ADA are two commonly used programming Imperative languages
(5)0bject Oriented Programming : The emphasis of this style is Procedural Module Object Generic
Towards
high level
based oriented
objects. Examples are C+, Java, ADA-95 and so on. programming
based languages
or statement based
u
anguages
lan
PPL
the algorithm of the
languao3) Simplicity: Due simplicity increases the readability of the
to
program
can
such components
in developing form
always interested
Ans.: Syntax is defines as a collection of rules that define the
for other applications.
is a feature by which the program o f alanguage. of rules: lexical
.Portability: Portability is defined by two set
other
m The syntax of language
a
modified to work on platfom
work on one platform can be
rule and syntactic rules.
Perspective and Early specific word classes.
That
1.5 A Brief Historical
The lexical rules affect in particular
High Level Languages of characters that
rules specify the rule for set
means, the lexical
scanf,
form a word. For example do, if, print,
-
can be combined to
level language along with their. use lexical rule.
Q.8 Enlist any four high
are all keywords in C.
This can be specified using the
purpose. which defined the particular
The syntactical rule has a wider scope
Ans.
defined by the lexical rule.
arrangement of words
Language Originator Year Purpose the context free grammar
For specifying the syntax of a language
COBOL Committee 1960 BusinessData Processing is used.
with the help of suitable
Q.10 Explain the concept of syntax diagrams
Pascal N.Wirth 1971 General Purpose
example.
the lexical rule and syntactic rules
D. Ritchie 1974 System Programming Ans.: Following example shows
for a simple program containing a_signment
statements only.
ADA J.Ichbiah 1979 General Purpose,
Embedde syntactic
ynt Rule
System
program> : = { <statement>*}
statement> :=<assignment>
<assignment> :=<identifier>=<expr>;
1.6 Language Definition
Kexpr>:=<identifier>| <number> |(<expr>)| <expr> <operator>
<expr>
Important points to Remember Lexical Rule
Every programming language has two major Com
Syntax and Semantics. ntsoperator> :=+|-|°|/|<|>|<=|>=
<identifier> :=<letter> <ld>*
Syntax represents form of a language | <digit>
kld>: <letter>
Semantic represents the meaning of alanguage.
PPL 1-10 Programming Lang1uage Syntar o
nd Sem
<number> := <digit> + 1-11 Programming LanguageSyntax and SemanticCS
PPL
<letter::= a|blc|...|z For example consider the C code fragment
<digit> := 0|1|2|....|9
The above rules can be represented using syntax diagra for(i=0;i<=10;i++)
program - 0 Begin
End
Thus these two constructs differ only at lexical level
statement concrete syntax specifications incude
Concrete Syntax : The
the tokens and keywords that allow parser to construct aan
a
statementassignment abstract syntax tree unambiguously. The concrete syntax tree will
retain all the information of input
assignment
identferE
0 + expr For example
expr Consider the context free grammar
expr operator expr E: E-+E
E = E*E
identifier E:num
The expression 2*3+4 can be derived aas
number
expr
Semantics
1-13 Programming Language Syntax and
Ans.: 1) Axiomatic Semantic PPL
Let,
.The axiomatic semantic is a semantic that is that is appropriatb a = expr
will be
arguing program correctness.
assignment statement. Then denotational semantic
be an
An axiomatic semantic consists of specified as
f) error for undefined variable in expr.
i) A language for stating assertions about programs. i) dsem (a:
=
expr, =
result
expr, f) =
i)dsem (a:
=
it isis for
expression But if there are more than single line
statements
variablex present in expr. Otherwiseexpr undefined apression not used {}.
have not t
result of evaluation will be will ined, Or
for sam
same then we have to enclose them within {}. There are chances to forget
then have to
returned. be we
en
evaluated and to add brackets for execution of multiple
statements. Hence
During interpretation of a language, every .Finally the complete program is loaded into the memory as
instruction is
executed. directly executable machine code. This task is carried out by loader.
Translators can be compilers and
assemblers
Programming Language Syntax and Seman 1-17 Programming Language Syntax and Semantics
1-16 PPL
PPL Source
The interpreters do not The compilers produce
program 2.
produce object code. object code.
For example
uses the combined two techni properties. These properties are called attributes.
The modern translation technique has number of
-translation and then interpretation. That means the source codethe
programming entity routine or function
methods and so
intermediate code and then the intermediate code parameters, type of parameters, parameter passing
translated into
on. Specifying the nature of attributes is called binding.
interpreted.
stored in data structure called
Q.18 Diferentiate betwen- Interpreter and compiler. The attribute description is a
Ans. descriptor.
Sr. No. The binding can be of two types static binding and dynamic
Interpreter Compiler
1.
binding
Demerit The source Merit: In the process When the attributes are bound at program translation time then it is
program gets interpreted
compilation the prog called static binding.
every time it is to be is
analyzed only once a When the attributes are bound at program execution time then it is
executed, and every time the then the code
source is called dynamic binding.
program analyzed. generated. Hen
Hence interpretation is
efficient than Ca
less compiler is efficient th
Programming Lang
I-18
PPL 1-19 Programming Language Syntax and Semantics
PPL 1.81.8 Varlables
In above code, there are three variables namely a,b and c. These
variables have the scope for entire function sum0. Outside the
Remember
Important
Pointsto function sum), these variables are not visible or accessible.
ofmemory
memory in which
which
name
for
reserved
area
som 2) Type
Variable is a
assignment statements.
char s;
attributes of variables
Q.20 Explain various Here the variable s is of type character. That means it allows the
Ans. value range from -128 to 127
Various attributes of
variables are
The language defines its in-built set of data types. These types are
called as reference.
be
accessed using pointer to poin sum (10, 20) Call
can
variable
unnamed
The
variable declare a variable of noi.
we can
In pascal the up-arTo void sum (int x, int y)
For exampie rrow
defined by pretixing
type is
integer. The pointer
with the base type. formal parameter
caret symbol (") n a m e d type because int 2
a is of Defnitton
/here variable
type a integer /accompanied with type
printi'Addition %d"', z)
and pointed by a
allocate an unnamed integer variable
We can
of type a
Q.23 Explain the positional method of binding.
newlaPtr): //unnamed varnable
perform specific task and can be repeatedly executed. For examp is parameter a is
Functions in C, Assembly language bound to parameter Formal parameters
subprograms, the subroutines
in FORTRAN, Procedures and x, parameter b is
Functions in Pascal and Ada.
The routines are usually handled by three ways bound to parameter
i) Declaration ii) call y and so on. Fig. Q.23.1 Positional method of binding
ii) definition For
Programmlng
Language nd Sem
Syntara n
PPL of generic
the
concept which implements the
implements
the des 1.10 An Abstract Semantic Process
. 2 4 Explain
routineisa
routine
concept
the concept of
of gen
In C++,
Am.:Generic
data type.
using
general .26 Write short note on abstract semantie processor.
algorithm templates.
outine is
achieved by using above code
code c a n be
can imn
be implemen Ans.: The abstract semantic processori is an abstract processor
C++ the above
In
kor example
follows
used for describing the operational semantics of programming
routine as
using generic
languages.
template <class T>
.It consists of instruction pointer, memoryand processor
T add(T a. Tb) The memory is a part where the instruction is executed and data to
be manipulated are stored. The memory is divided into two parts -
TC
Ca+b code memory and data memory. The code memory is denoted by
return c; array C[location_Index] and data memory is denoted by array
jumpt(based on condition)
Fig. Q.25.1
Syntarand
1-24
Programming
Language
Semam
polnter PPL 1-25 Programming Language Syntaxand Semantics
PPL
I n s t r u c t i o n
Memory
instruction
pointer | Hence there are three allocation methods used during run time
The the
to structure. These are
points
always
code
instruction in the 1. Static allocation The static allocation is for all the data objects at
memory. compile time.
Following Fig. Q,26.l
2. Stack allocation In the stack allocation astack is used to manage
machine shows abstract
the run time storage.
machine Code memory Data memon 3. Heap allocation In heap allocation the heap is used to manage
the dynamic memory allocation.
Fig. Q.26.1
Abstract semantic processor 1.12 Case Study: Run Time Structure of C
1-26 code
without ree. PPL 1-17 Programmimg LanguageSyntax and Semanties
forward
PPL straight for abstract
is a straignllocated for abstract semang. Temporary values
s.
The temporary variables are needed during
code is a allocated
makes use of a d data in other activation record. This field is aiso cailed static link
For stack allocation technique, C program
record. field.
structure popularly known as activation
5. Actual parameters This field holds the information about the
Q.29 Write short note on Activation record.
-
Ans.
actual parameters. These actual parameters are passed to the called
else (n-1)
PL 1-29 Programming Language Syntax and Semantics
f a c t o r i a l
Third call
main)
1-30 Programming Language Syntax
PPL and Sene
{1, 1}; 1-31 Programming Language Syntax and Semantics
inta12 PPL
int b[3 {1, 2, 0} x1,y-0. The x and y values get swapped. But on returning
pali), a[i]); main, the x and y values do not get preserved.
printf"%d, %dn", a[0},
a[1); values. Therefore
The printf statement is for printing b[o] and b[2]
Swapj. a]) we will get 1 2 0.
printf"%d.%d, %dn", bj0], b[1], b[2); Hence output will be
return 0; 1
1 2 0
Ans.: i) Call by value
When Plali], ali] ) is called then
i) Call by reference
In call by reference, the formal parameters get associated with
P(1.1)
actual parameter.
P(x.y) void p(int x, int y)
In the function body P, x and y will be increment. Hence x =
"/
i- 2, y 2. But
x+ 1 x becomes 2, y becomes 2
=
on returning to main, the x and y values will not i+ 1 i = 1/
preserved. y+ 1 y becomes 3 /
printf(" %d %d", a[0], a[1] ) will result as 11
When control returns to main a[0] = x = y =3 and a[1] remains as
When call to swap (j, a[ji] Dgiven it will be
it is i.e. 1.
swap (x, y) After calling swap function the printf statement is printing b[0],
swap (0, 1) b[1] and b[2] i.e. 1, 2, 0.
In the function body of x Hence output will be,
x X+y 3 1
i.e x 0 + 1 =1 1 20
yx-y l) Call by value result
y 1 - 1 =0
xX-Y In call
by value result the actual parameter applied by the caller is
x 1-0 copied into callee's formal parameter the function executes and then
X formal parameter is copied back to caller. No alias or reference is
created between formal and actual parameters. Hence
OECOD Less then
PHOTOcOPY
Less than PHOTOCOPY Price
PPL vntax and Semant
void plint x, int y)
2
{
al0] x, a[0] y Structuring of Data,
i.e.
X+ 1
X1+1=2
Computations and Program
yt 1
i.e. y 1+1 2
2.1 Buit in and Primitlve Types
On returningg to main value of x gets copied to
a[0].. afo. al0] Important Points to Remember
The a[l] remains 1. After swap function tne printr prints
d[u}, b[1]a. Any programming language has
b[2). predefined set of built in
data
Hence output will be, types.
2 1 Programming language support various built in data types such as
1 20
boolean, character, integer and reals.
v) Call by name
Q.1
Explain buit in types of programming languages.
In this method the actual
parameters will be substituted for all Ans.: Any programming language has a predefined set of built in data
occurrences of formal
parameter. tnes This built in data type reflects the behavior of
ypes underiying
Hence hardware.
p( int x, int y) Due to
builtin data type, the values are interpreted differently
plalol, a[1D using hardware instructions.
mCisapimitive data type which is used to define new constamThe intensional mapping is a routine in which the range type
values are directly associated with domain type values.
22:Data Aggregates and Type Constructors
Finite Mapping
.Forexample - objects. values are associated as data aggregates. For exampie int a(S].
s
similar date type
elements Constructor is aggregation Here integers from subrange 0 to 4 are mapped althougn tnis
which element corresponds to the
declaration does not specity
Q.3 What is Cartesian
constructor? product ? How it is particular subrange.
useful to denote D
Ans.: The cartesian In extensional mapping using indexing technique the elements are
In extensional
product of n sets
A, Aj, A
u*s
AAg Aj, , A, mapped in given subrange. For example
A As is a set whose el
xA, is a set whose elements are denoted
A, denoted ...,
Q.6 Explain the concept of 3. The static type checking is The dynamic type checking
type systems.
Ans.: Definition: also called as compile time | is also called as execution
The type system is defined of rules use
as set
the language to structure and time checking.
organize its collection of various typ | checking.
Type systems play
semantics of a languagc.
an
important role in determining
2-6
Structuringof Data, &Progre
Computatons
two types
There are
explicit conversion.
Coercion a.13 Write short note on type structure of C++.
Ans. : The type
structure is divided into two main categories
of C++
- Fundamental types and Derived Types.
Explicit conversion
The fundamental type is integer and float. The integer data type
-
Implicit conversion
stack data
structure using class,
class.
creates a For example
class
The above
note on type
structure of Java. 19+(10+3 7)/(20-3*2)
Q.14 Write short in two Consider an expression
classified two categ0
of Java is
structure
Ans. The type will evaluate () first.
2. Derived Types. Step 1:We
1. Built in Data Types * 7=21. Then perform 10 21 31.
Javedat type structure
Step 2:Evaluate 3
** 2=9. Then 20-9 11.
Step 3: Evaluate 3
Buit-in Compoete 31/11 =2.
Step 4:Perform
+2=21.
Floaeng pol Class A T a y e Stpe 5: Perform 19
The tree representation will be
2-12
Structuringof Data,
written
&Prog PPL 2-13
Structuring of Data, Computations &Program
PPL
otherwise b this
statement
can be
sing
usi.
i) Procedures
ii) Functions
then a a kind
Procedure is ai of routine that does not return
follows- a value. On the
conditional expression as
(a>b)?a.b other hand, functions return a value.
written as ides both procedures and functions. The formal
Pascal provid
In ML it is
a else b
Ifa> b then can be-by value or by reference.
parameters
par
Procedure in Pascal
Example of
P r o c e d u r e
MaxNum (x, y: integer, var z : integer)
Execution and Iteration
2.6:Conditional
begin
if x>ythen
controls.
forms of statement level
Z: X
Q.17 Explain different
controls
forms ofstatement level else
-
again.
result integer
begin
if (x > y) then
2.7: Routines
result: =x
else
Important Points to Remember
Routines are collection of statements that are
result:= y:
to be MaxNum: = result;
repeatedly. execute
end
Routines are of two types
Procedures and Functions 2.8:Style Issues:Side Effects and Allasing
-
(DECADGYa
2-14
Strucmringof Data, utations& Pro
Comwpntao.
PPL read,
understand andmodi
dify. Ther 2-15 Structurtng of Data, Computatlons &Program
becomes
difficult to
might be
modified in
n
chances that the variables onl
nono Thus assignment to one variable affect the value in another
ariable.
environment.
of error
due to unrestricte
unrestrine.
2) Finding
ermors or
cause
use 2.9: Exceptions
non-locals become complex.
reference ImportantPoints to Remember
passing by
S i d e effect of parameter of
Definition of Exception Excenti
Exception: Exception can be defined as an
the actual parameter
might get modis
There are chances that undesirable condition that occurs in the program.
to parameter passing by' reference. Definition of Exception Handling: Exception handling
Side effect of function : As procedures do not return a value, mechanism by which the language can recognize the unexpected
is a
, the
are less side effects of procedures. However, there are seriousSisundesirable and anomalous behavior and specify the response
effects offunction.For example codethat must beexecuted when the exceptionis raised.
Q.20 Explain exception handling mechanism in C++
result: a + fun(a, b) ;
Ans.:C+ exception handling mechanism makes use of three
.In above statement, if function fun uses parameter passing keywords try, catch and throw. The try represents the block of
reference, then fun might produce a change in a or b 1) T statementsin which there are chances of occurring some
reduces the readability of program. exceptional conditions.
2)Another side effect is such statements prevent compileWhen exception detected it is thrown using the throw statement.
from generating optimized code. There exists a block of statements in which the exception thrown is
handled appropriately. This block is called catch block
Side effect Aliasing: The two variables
of are said to be
aliasesi
they share the same data object Following figure illustrates the concept of exception handling
during
unit activation. For exampk
consider following code firagment mechanisms-
mechanisms -
PPL
3
2-16