CS3201/2: Software Engineering Project: SPA Requirements Analysis
CS3201/2: Software Engineering Project: SPA Requirements Analysis
Project
SPA requirements analysis
LN Set #2
Motivation
Some companies spend up to 80% of the total computer
budget on software maintenance.
During maintenance, programmers spend 50% trying to
understand a program.
What do programmers need to know to understand programs:
I need to find code that implements salary computation rules!
Where is variable x modified? Where is it used?
I need to find all statements with sub-expression x*y+z
Which statements affect value of x at statement #120?
Which statements can be affected if I modify statement #20?
CS3201/2 Set #2 SPA
application
domain
detailed
globalprogram
program
program design
design
requirements
code
formulate query
query
retrieve information
query result
analyze information
no:
refine query
is info relevant?
complete?
UI to enter program
source program
in SIMPLE
UI to view
query result
UI to enter
queries
SPA
front-end
query result
query in PQL
design abstractions
Program
Knowledge Base
PKB
design abstractions
Query Processing
Subsystem
Basics of SPA
Source language SIMPLE
Types of information stored in PKB
Query Language PQL
Common program queries
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
CS3201/2 Set #2 SPA
procedure Third {
z = 5;
v = z; }
10
Program statements:
Procedure call: call p
Assignment: x = 2;
x = a + 2 * b;
11
Syntax of SIMPLE
Meta symbols:
Lexical tokens:
DIGIT : 0-9
procedure, variable and attribute names are strings of letters, digits, starting with a letter
INTEGER : DIGIT+
12
13
14
program : procedure+
program : procedure+
stmtLst : stmt+
stmt : call | while | if | assign
stmtLst : stmt+
var_name : NAME
proc_name : NAME
const_value : INTEGER
CS3201/2 Set #2 SPA
15
16
17
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
CS3201/2 Set #2 SPA
procedure Third {
z = 5;
v = z; }
18
First:procedure
Second:procedure
Sibling
:stmtLst
:assign
x:variable
:stmtLst
:assign
2:constant
Third:procedure
z:variable
Second:call
3:constant
:assign
x:variable
0:constant
:assign
i:variable
5:constant
19
:if
Follows
Parent
Parent
:stmtLst
i:variable
Parent
x:variable
:assign
Parent
z:variable
:plus
z:variable
1:constant
:plus
:plus
:assign
:assign
:plus
x:variable
else:stmtLst
then:stmtLst
Third:call
:assign
Follows
z:variable
i:variable
x:variable
x:variable
x:variable
:times
2:constant
x:variable
1:constant
y:variable
20
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
4,5,6
10,11,12
21
22
23
Examples
Queries
What to store
..
24
25
26
Example: Calls
Example: A typical query - Is procedure p6 called from p2 in a chain of
procedure calls?
Calls (p2, p6) ?
Calls* (p2, p6) ?
27
28
Call (statement)
stmtLst
While (statement)
stmt
If (statement)
prog_line
variable
assign (statement)
constant
29
Relationship between
Uses
Statement/Assignment/Procedure
and
Variable
Statement/Assignment/Procedure
and
Variable
Modifies
30
Relationship between
Statements
Parent/ Parent*
Statements
Calls/ Calls*
Procedures
Next/ Next*
Program lines
Affect/ Affect*
31
Uses
Design entities
Description
Assignment a
Variable v
Container statement s
(i.e. if or while)
Variable v
Procedure p
Variable v
32
Examples of Uses
procedure First {
x = 2;
z = 3;
call Second; }
procedure Third {
z = 5;
v = z; }
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
33
Modifies
Design entities
Description
Assignment a
Variable v
Container statement s
(i.e. if or while)
Variable v
Procedure p,
Variable v
34
Examples of Modifies
procedure First {
x = 2;
z = 3;
call Second; }
procedure Third {
z = 5;
v = z; }
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
35
36
Follows* (1, 6)
37
38
39
40
procedure Third {
z = 5;
v = z; }
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
41
42
Examples of Next
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
1,2
B. Next (3, 4)
3
C. Next (3, 7)
D. Next (5, 6)
4,5,6
E. Next (6, 4)
F. Next (7, 9)
G. Next (7, 10)
H. Next (8, 9)
I. Next (8, 10)
CS3201/2 Set #2 SPA
10,11,12
43
Examples of Next*
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
A. Next* (1, 2)
B. Next* (1, 3)
C. Next* (2, 5)
D. Next* (4, 3)
4,5,6
E. Next* (5, 2)
F. Next* (5, 5)
G. Next* (5, 8)
I. Next* (8, 9)
CS3201/2 Set #2 SPA
44
Affects
Affects (a1, a2) holds if
a1 modifies a variable v which is used in a2.
there is an execution path from a1 to a2 on
which v is not modified
Affects (1, 2)?
1. x = 5;
2. y = x;
1. x = 5;
2. y = z;
if z then {
1. x = 5;}
else {
2. y = x;}
CS3201/2 Set #2 SPA
1. x = 5;
x = 10;
2. y = x;
45
46
procedure q {
6. x = 5;
7. if z then {
8. t = x + 1; }
else {
9. y = z + x; } }
47
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
1,2
A. Affects (2, 3)
B. Affects (2, 6)
C. Affects (4, 8)
D. Affects (4, 10)
4,5,6
E. Affects (9, 6)
F. Affects (9, 11)
G. Affects (6, 6)
8
procedure Third {
z = 5;
v = z; }
CS3201/2 Set #2 SPA
10,11,12
48
Affects*
Affects* (a1, a2) holds if
a1 affects a2 directly or indirectly
Example: Affects* (1, 2), Affects* (2, 3),
Affects* (1, 3)
1. x = a;
2. v = x;
3. z = v;
49
Examples of Affects*
procedure Second {
1. x = 0;
2. i = 5;
3. while i {
4.
x = x + 2*y;
5.
call Third;
6.
i = i - 1; }
7. if x then {
8.
x = x+1; }
else {
9.
z = 1; }
10. z = z + x + i;
11. y = z + 2;
12. x = x * y + z; }
1,2
A. Affects* (1, 4)
3
4,5,6
procedure Third {
z = 5;
v = z; }
CS3201/2 Set #2 SPA
10,11,12
50
51
52
Query results must check (make true) all such that, with and
pattern clauses
CS3201/2 Set #2 SPA
53
54
55
56
57
Examples of patterns
Which of the patterns match with this assignment statement?
x=v+x*y+z*t
A.
a ( _ , v + x * y + z * t)
B.
a ( _ , v)
C.
a ( _ , _v_)
D.
a ( _ , _x*y_)
E.
a ( _ , _v+x_)
F.
a ( _ , _v+x*y_)
G.
a ( _ , _y+z*t_)
H.
a (_, _x * y + z * t_)
I.
a ( _ , _v + x * y + z * t_)
58
x*z
x+y+z
+
*
z
*
z
z*5+x
+
x+z*5
+
x
*
5
y
(x + z)*5
*
5
x
CS3201/2 Set #2 SPA
5
z
59
x+z
+
x*z
x+y+z
+
*
z
*
z
z*5+x
+
x+z*5
+
x
*
5
y
(x + z)*5
*
5
z
60
Examples of pattern
Which of the patterns match with this assignment statement?
x=v+x*y+z*t
A.
a ( _ , v + x * y + z * t)
B.
a ( _ , v)
C.
a ( _ , _v_)
D.
a ( _ , _x*y_)
E.
a ( _ , _v+x_)
F.
a ( _ , _v+x*y_)
G.
a ( _ , _y+z*t_)
H.
a (_, _x * y + z * t_)
I.
a ( _ , _v + x * y + z * t_)
+
+
*
v
x
*
z
61
62
63
Q. Find assignments that contain sub-expression x*y+z on the right hand side.
assign a;
Select a pattern a ( _ , _x*y+z_)
-- answer: statement #12
64
65
66
67
assign a; while w;
Select a such that Modifies (a, x) and Parent* (w, a) and Next* (1, a)
Select a such that Parent* (w, a) and Modifies (a, x) and Next* (1, a)
Select a such that Next* (1, a) and Parent* (w, a) and Modifies (a, x)
Select a pattern a (x, _) such that Parent* (w, a) and Next* (1, a)
Select a such that Parent* (w, a) and Next* (1, a) pattern a (x, _)
Select a such that Next* (1, a) and Parent* (w, a) pattern a (x, _)
-- answer: statement #4
BUT: Changing the order of conditions may affect query evaluation time
68
Format of Result
Select
Should return
BOOLEAN
TRUE/FALSE
Statement s(a/n/c/w/ifs)
Program line pl
Statement number
Variable v
Procedure p
Constant ct
Constant value
StmtLst sl
69
Summary
This lecture covered
(i) What is SPA and how does it work.
(ii) Source Language SIMPLE
(iii) Program Design abstractions for SIMPLE
(iv) Rules for writing Program Queries in PQL
70
PKB
PQL
Relationships
AST
Clause
CFG
Synonym
Patterns
Attribute
CS3201/2 Set #2 SPA
71
72