-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht9.txt
304 lines (279 loc) · 9.7 KB
/
t9.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
** Test case 9: Testing execution flow statements - switch and for
This Includes
1. Switch variable type and case values plus the presence of default statement
2. Whether the loop variable is not assigned a value in for loop
3. A function with the same name cannot appear more than once (overloading check)
4. A function cannot call itself (recursion check)
5. precedence of function definitions before their use
6. Assignment of output parameters
7. Number and types of input and output parameters (extension of test case 6)
8. static bound checking and static type checking in expressions - arithmetic and boolean (extension of test case 5) **
** Multiple level nesting using integer, real, boolean data types including static array data type**
**Variant of test case 8**
declare module function1;
declare module function2;
declare module function4;
declare module switch_int_default;
<<module switch_var_demo1>>
takes input [x: integer, y: real, z:boolean];
returns [u: integer];
start
declare m,n,k: integer;
declare h:boolean;
declare p: real;
get_value(n);
switch(k)
start
case 10: declare A:real;
declare Q: integer;
declare B: array[10..30] of integer;
declare E: array[4..10] of integer;
B[12]:= k*20;
break;
case 20: A:= 12.90 + p;
get_value(Q);
for(m in 10..15)
start
n:= n+m;
end
E[7]:= k+12 - Q*10;
break;
case true: m:=m-n; **ERROR: Case value is incorrect as condition variable type is integer**
break;
default: E[9]:= B[15]+Q;
break;
end
u:= u+ x*m-n;
use module switch_int_default with parameters n;
switch(p) **ERROR: switch variable cannot be of type real**
start
case 1: p:=p+1; ** a type error, but not reported as the traversal skips the subtree due to invalid type of variable used in the switch.**
break;
default:h:=false;
break;
end
switch(h)
start
case false: declare A:real;
declare Q: integer;
declare B: array[10..30] of integer;
declare E: array[4..10] of integer;
B[12]:= k*20;
break;
case 20: A:= 12.90 + p; **ERROR: Case value is incorrect as condiiton variable type is boolean**
get_value(Q);
for(m in 10..15)
start
n:= n+m;
end
E[7]:= k+12 - Q*10;
break;
case true: m:=m-n;
print(m);
break;
default: E[9]:= B[15]+Q; **ERROR: presence of default statement is incorrect as condiiton variable type is boolean**
break;
end
end
<<module for_loop_demo>>
takes input [x: integer, y: real, z:boolean];
returns [u: integer];
start
declare k: integer;
for(k in 12..70)
start
u:= x+k;
k:= k+2; **ERROR: for loop variable k cannot be assigned a value**
end
end
<<module var_demo_array>>
takes input [x:integer, m:array [2..20] of integer, p:real];
returns [ n:integer, k: boolean];
start
declare a,b,h:integer;
get_value(b);
declare b4: array[100..150] of boolean;
declare p: array[2..20] of integer;
a:= m[5]+3; **Not an error: array index within bounds**
use module function2 with parameters a,b; **not an error as module function2 is declared before this call**
p:= m; **Not an error: type expressions of array variables p and m are same and assignment is a valid operation**
k:=true;
p:= m + p; **ERROR: array variables m and p cannot be added**
declare v1, v2:real;
p[10]:= a*b-20*h; **Not an error: array index within bounds**
declare b7: array[35..50] of real;
while(k AND x<=m[11] OR false)
start
declare p, u:integer;
declare b: array[2..20] of integer;
declare b5, b6: array[35..50] of real;
b:= m;
[v1, u, k, p]:=use module function1 with parameters b4, v2, p, b5, u; **not an error**
b[2]:= u+m[25]; **ERROR: element of array m is out of bound**
p:= b[18]*18.56E+2; **ERROR: type mismatch **
declare v3:integer;
[v1, u, k, v3]:=use module function1 with parameters b4, v2, p, v3, u; **ERROR: input parameter type mismatch **
end
a:= a - p*b; **ERROR: types of p and b are different**
b:= b+3;
k:= a>b OR b>100;
[v1, a, k, h]:=use module function1 with parameters b7, v2, p, b7, b; **ERROR: input parameter type mismatch **
print(k);
end ** ERROR: Output parameter n is not assigned any value **
<<module function2>>
takes input [ x:integer, y:integer];
start
declare temp: integer;
use module function2 with parameters x,y; **ERROR: Function cannot call itself**
temp:= x+y;
end
<<module f1>>
takes input[a: array[10..30] of integer, b:array[10..30] of integer, c:real];
returns [m:boolean, n:integer];
start
declare x,y, p: real;
declare k, y1: integer;
declare E: array[2..20] of integer;
declare Var3, Var4: array[100..150] of boolean;
get_value(y);
get_value(x);
declare A,B: array[4..10] of integer;
declare Var1, Var2: array[35..50] of real;
get_value(B);
use module function2 with parameters k, y1; **Do not report this as an error because of redundant declaration of function2. This declaration has been genuinely needed in function var_demo_array**
declare D,C: array[10..30] of integer;
A:=B;
[ y1, m]:=use module var_demo_array with parameters k,E,x; **not an error**
C:=a;
[x, y1, m, k]:=use module function1 with parameters Var3, c, k, Var2, k; **no error**
D:=C;
[ k, m]:=use module var_demo_array with parameters k,B,p; **ERROR: Input parameter type of B does not match with formal parameter type**
for (k in 15..40)
start
x:=x+k*y; **ERROR: Type mismatch error**
declare u, v:real;
declare int1, int2: integer;
u := y+c*34.2;
v:= u-c*p-20.5E+2;
[x, int1, m, int2]:=use module function1 with parameters Var3, c, k, Var4, k; **ERROR: Input parameter type of Var4 does not match with formal parameter type**
switch(k)
start
case 10: declare A:real;
declare Q: integer;
declare B: array[10..30] of integer;
declare E: array[4..10] of integer;
B[9]:= k*20; **ERROR: element of array B is out of bound**
B:=C; **not an error**
E:= Q; **ERROR: variables E and Q are of different types **
break;
case 20: A:= 12.90 + u*y - c;
[A, Q, u, y1]:=use module function1 with parameters Var3, c, k, Var1, int1; **ERROR: Output parameter type of u does not match with formal parameter type**
get_value(Q);
E[7]:= k+12 - Q*10+u; **ERROR: Type mismatch error**
break;
default: E[9]:= B[15]+Q; **not an error**
[A, Q]:=use module function1 with parameters Var3, c, k, Var1, int1; **ERROR: Number of output parametters does not match with that of formal parameters**
break;
end
x:=x + u*v- u<=v; **ERROR: Type mismatch error**
end
x:=c+y;
[p]:= use module function3 with parameters x,y; **ERROR: module function3 is not defined**
C[18]:= a[18]+ b[18];
A[5]:= B[6]- 10;
m:= A[5]< C[18] + A[11]; **ERROR: element of array A is out of bound**
y1:= 20*8-5;
end ** ERROR: Output parameter n is not assigned any value **
<<module function3>>
takes input [a: real, b:real];
returns [c:real];
start
c:= a+b;
end
<<module function4>> **ERROR: function4 definition and its declaration both appear before its call**
takes input [a: boolean, b:boolean];
returns [c:boolean];
start
c:= a AND b;
end
<<module function3>> **ERROR: function3 cannot be overloaded**
takes input [a: real, b:boolean, e:integer];
returns [c:boolean, d: integer];
start
d:= 5*43+e;
c:= a<15.50 AND b;
end
<<<driver program>>>
start
declare v_1_2_3, A:integer;
declare u1, u2, k:boolean;
A:=12;
declare p: real;
[k]:= use module function4 with parameters u1, u2;
p:= 23.56;
get_value(v_1_2_3);
declare B, C: array [2..20] of integer;
[ v_1_2_3, u1]:=use module var_demo_array with parameters A,B,p;
[ v_1_2_3, k]:=use module var_demo_array with parameters A,B,p;
declare a,b:integer;
a:= 5.89e-2; **ERROR: type mismatch error**
get_value(b);
declare value, q, r: real;
get_value(q);
r:= 23.67e+2;
value:= p+q*r-a*value; **ERROR: type mismatch error**
k:= true AND false OR q; **ERROR: type mismatch error**
u1:= a<=b;
declare w: integer;
w:= 23+B[6];
b:= a*25+100*C[1]; **ERROR:element of array C is out of bound**
declare D: array[20..40] of integer;
D:= value-q+r; **ERROR: type mismatch error**
w:= w + 5;
B:= C;
C:= D; **ERROR: type mismatch error**
end
<<module function1>>
takes input [data: array[100..150] of boolean, weight: real, length: integer, b:array[35..50] of real, q:integer];
returns [R1: real, R2: integer, R3: boolean, R4: integer];
start
declare e,f: integer;
declare g,h: array[100..150] of boolean;
get_value(g);
h:=data;
h[120]:= g[120] OR length<=q AND h[140];
declare a: real;
declare p1: boolean;
R2:= q+1;
get_value(a);
[R1, e, p1, f]:=use module function1 with parameters g, a, e, b, f; **ERROR: function cannot call itself **
R1:= a+weight/20.50;
R4:=f + 100;
end ** ERROR: Output parameter R3 is not assigned any value **
<<module function1>> **ERROR: function1 cannot be overloaded**
takes input [b:boolean, e:integer];
returns [c:boolean, d: integer];
start
d:= e+15;
c:= true AND b;
end
<<module switch_int_default>>
takes input [x:integer];
start
declare a, b: integer;
declare c: real;
declare d: boolean;
x:= a+b;
[a]:=use module for_loop_demo with parameters b, c, d;
switch(a)
start
case 1: a:=a+b;
break;
case 2: a:=a-b;
break;
case 3: a:= a*b;
break;
case 4: a:= a/b;
break;
end **ERROR: default statement is missing- the type of switch variable is integer**
end