-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtestcase2.txt
52 lines (45 loc) · 1.43 KB
/
testcase2.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
%Test Case 2
%Following program computes the average marks obtained by students in three subjects
%Following function reads marks of a student in all subjects and returns as a record variable
% Note that the variable b7 is not used anywhere but it is the syntactic requirement to have
% atleast one input parameter
_readMarks input parameter list[int b7]
output parameter list [ record #marks b3c45];
read(b3c45.maths);
read(b3c45.physics);
read(b3c45.chemistry);
return [b3c45];
end
% Notice here that your compiler recognizes the type definition of marks even before it is
% declared. This will be handled at the semantic analyzer phase.
%The following program computes the average of marks of total d5cb34567 students
_main
record #marks
type real : maths;
type real: physics;
type real: chemistry;
endrecord;
% each field above represents the marks obtained in corresponding subject
type record #marks : d4;
% The variable d4 stores the marks of one student
type int : b5;
type int : d5cb34567;
type record #marks : b5c6;
%The identifier b5c6 stores the sum of marks
b5 <--- 1;
read(d5cb34567);
b5c6.maths <--- 0.00;
b5c6.physics <--- 0.00;
b5c6.chemistry <---0.00;
while(b5<=d5cb34567)
[d4] <--- call _readMarks with parameters [b5];
b5c6 <--- b5c6 + d4;
% above displays the sum of records
b5 <--- b5 +1;
endwhile
d4 <--- b5c6 / d5cb34567;
write(d4.maths);
write(d4.physics);
write(d4.chemistry);
return;
end