-
Notifications
You must be signed in to change notification settings - Fork 2
/
testcase4.txt
56 lines (54 loc) · 1.5 KB
/
testcase4.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
declare module readArr;
**the following function computes the sum of first n elements of the array**
<<module arraySum>>
takes input[list:array[1..15] of real, n:integer];
returns [sum:real];
start
declare index:integer;
declare t:boolean;
sum:=0.0;
for(index in 1..15)
start
t:= index<=n;
switch(t)
start
case true: print(list[index]);
sum:=sum+list[index];
break;
case false: print(sum);
print(index);
**prints the values of sum and index 15-n times**
break;
end
** no need to increment the value of index as it will be taken care by the semantic rules associated with for construct, but an increment statement does not make its syntax incorrect**
end
print(sum);
end
<<<driver program>>>
start
declare A:array[1..15] of real;
declare k:integer;
declare s:real;
get_value(k);
use module readArr with parameters A,k;
[s]:= use module arraySum with parameters A,k;
print(s);
end
**The following module reads k values one by one**
** the array elements are populated with the read values**
**The array variable is not returned as the translation will**
**use the same locations for array elements**
<<module readArr>>
takes input [arr1:array[1..15] of real,k:integer];
start
declare tempvar:real;
declare i:integer;
i:=1;
while(i<=k)
start
get_value(tempvar);
arr1[i]:=tempvar;
i:=i+1;
** the semantics of while needs an increment and will be taken care of at the second phase**
end
end