0% found this document useful (0 votes)
2 views

SRE_Assignment_1

The document outlines an assignment for a Software Re-Engineering course at COMSATS University Islamabad, focusing on program slicing techniques. It includes definitions of REF(n) and DEF(n), and provides multiple programming examples where students must compute relevant sets and backward static program slices. The assignment emphasizes understanding the relationships between variables in code statements and their influence on program execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SRE_Assignment_1

The document outlines an assignment for a Software Re-Engineering course at COMSATS University Islamabad, focusing on program slicing techniques. It includes definitions of REF(n) and DEF(n), and provides multiple programming examples where students must compute relevant sets and backward static program slices. The assignment emphasizes understanding the relationships between variables in code statements and their influence on program execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

COMSATS University Islamabad, Vehari Campus

Department of Computer Science

Semester – Spring2025

Subject: CSE327-Software Re-Engineering Class: BS (SE)


Instructor: Dr. Manzoor Ahmad Due Date: 05-04-2025

Assignment 1:
CLO2-Applying Topic: Program Slicing
• REF(n) – the set of variables that are referenced in n
• DEF(n) – the set of variables defined (given a value) in n
• Relevant sets for the slice taken with respect to <n,v> are computed as follows:
o 1. Initialize all relevant sets to the empty set.
o 2. Insert variable v into relevant(n).
o 3. For m, n’s immediate predecessor, assign relevant(m) the value
relevant(m) = (relevant(n) – DEF(m)) U (REF(m) if relevant(n) ∩ DEF(m) ≠ {})
o 4. Working backwards, repeat step 3 for m’s predecessors until ninitial is reached
Assignment Statement
Consider the following questions and compute the
• REF(n),
• DEF(n) and
• relevant(n) according to (above define method) for each statement of each program.
Find the Backward Static Program Slice of each program according defined program slicing
criterion.
A sample solution for your guidelines is the last.

1
Program #1
n Statement REFs(n) DEFs(n) relevant(n)
1 b= 1
2 c= 2
3 d= 3
4 a= d
5 if (a= 3) then
6 d= b + d
7 c= b + d
8 else
9 b= b + 1
10 d= b + 1
11 Endif
12 a= b + c
13 print a
Program Slice on <13, a> =?
Program #2
n Statement REFs(n) DEFs(n) relevant(n)
1 #include <stdio.h>
2 #include <math.h>
3
4 int main(void)
5 {
6 Double a, b, c, d, x1, x2;
7 // Read input data
8 printf(“Enter the variables for the
quadratic”);
9 scanf(“%If%If%If”, &a, &b, &c);
10
11 //Perform calculation
12 d=sqrt(b * b – 4. * a. *c);
13 x1=(-b + d) / (2. *c);
14 x2=(-b – d) / (2. *a);
15
16 //Display output
17 printf(“\nx1= %12.3e x2=
%12.3e\n”, x1, x2);
18 return 0;
19 }
Program Slice on <17, x2> =?

2
Program #3
n Statement REFs(n) DEFs(n) relevant(n)
1 b= 1
2 c= 2
3 d= 5
4 a= 3
5 While (a < 10)
6 b= b + c
7 c= c + 1
8 a= b
9 EndWhile
10 print a
Program Slice on <10, a> =?
---------------------------------------------------------------------------------------------------------------
Program #4
n Statement REFs(n) DEFs(n) relevant(n)
1 read(text);
2 read(n);
3 lines= 1;
4 chars=1;
5 subtext = “”;
6 c= getChar(text);
7 while (c!= ‘\eof’)
8 If (c== ‘\n’) then
9 lines = lines + 1;
10 chars = chars + 1;
11 else chars=chars + 1;
12 if(n!= 0) then
13 subtext = subtext ++ c;
14 n=n - 1
15 c= getChar(text);
16 write(lines);
17 write(chars);
18 write(subtext);
Program Slice on <18, subtext> =?
-------------------------------------------------------------------------------------------------------------

3
Program #5
n Statement REFs(n) DEFs(n) relevant(n)
1 read(n);
2 i=1;
3 sum=0;
4 product=1;
5 while (i < n) do
6 sum= sum +i;
7 product= product *i;
8 i=i +1;
9 write(sum);
10 write(product);
Program Slice on <10, product> =?
---------------------------------------------------------------------------------------------------------------------------------------------------------

4
Sample Program Slicing (Backward static):
n Statement REFs(n) DEFs(n) relevant(n)
1 b=1 b
2 c=2 c b
3 d=3 d b, c
4 a=d d a b, c
5 d=b +d b, d d b, c
6 b=b + 1 b b b, c
7 a= b + c b, c a b, c
8 Print a A a

Program Slice on <8, a>: {7, 6, 2, 1} is given below.


n Statement
1 b=1
2 c=2
6 b=b + 1
7 a= b + c

The relevant sets for slice with respect to <8, a). The relevant sets are computed from Line 8 to
Line 1.
relevant(8) = a
relevant(7) = (relevant(8) – DEF(7)) U (REF(7) if relevant(8) ∩ DEF(7) ≠ {})
relevant(7) = ({a} – {a}) U ({b, c} if {a}∩ {a} ≠ {})
relevant(7) = {b, c}
-----------------
relevant(6) = (relevant(7) – DEF(6)) U (REF(6) if relevant(7) ∩ DEF(6) ≠ {})
relevant(6) = ({b, c} – {b}) U ({b} if {b, c}∩ {b} ≠ {})
relevant(6) = {c} U {b} = {b, c}
-----------------
relevant(5) = (relevant(6) – DEF(5)) U (REF(5) if relevant(6) ∩ DEF(5) ≠ {})
relevant(5) = ({b, c} – {d}) U ({b, d} if {b, c}∩ {d} ≠ {})
relevant(5) = ({b, c} – {d}) = {b, c}
-----------------
5
relevant(4) = (relevant(5) – DEF(4)) U (REF(4) if relevant(5) ∩ DEF(4) ≠ {})
relevant(4) = ({b, c} – {a}) U ({d} if {b, c}∩ {a} ≠ {})
relevant(4) = ({b, c} – {a}) = {b, c}
------------------
relevant(3) = (relevant(4) – DEF(3)) U (REF(3) if relevant(4) ∩ DEF(3) ≠ {})
relevant(3) = ({b, c} – {d}) U ({} if {b, c}∩ {d} ≠ {})
relevant(3) = ({b, c} – {d}) = {b, c}
------------------
relevant(2) = (relevant(3) – DEF(2)) U REF(2) if relevant(3) ∩ DEF(2) ≠ {})
relevant(2) = ({b, c} – {c}) U ({b, c} if {}∩ {c} ≠ {})
relevant(2) = ({b, c} – {c} = {b}
------------------
relevant(1) = (relevant(2) – DEF(1)) U (REF(1) if relevant(2) ∩ DEF(1) ≠ {})
relevant(1) = ({b} – {b}) U ({} if {b}∩ {b} ≠ {}) = {}

You might also like