-
Notifications
You must be signed in to change notification settings - Fork 0
/
t5.txt
208 lines (201 loc) · 5.14 KB
/
t5.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
**
. moduleDeclarations . . NT
. ID . readArr . moduleDeclarations . T
. otherModules . . NT
. MODULE . module . otherModules . T
. ID . arraySum . MODULE . T
. input_plist . . MODULE . NT
. ID . list . input_plist . T
. ARRAY . array . ID . T
. NUM . 1 . ARRAY . T
. REAL . real . ARRAY . T
. ID . n . input_plist . T
. INTEGER . integer . ID . T
. RETURNS . . MODULE . T
. output_plist . . RETURNS . NT
. ID . sum . output_plist . T
. REAL . real . ID . T
. statements . . MODULE . NT
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . index . idList . T
. INTEGER . integer . DECLARE . T
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . t . idList . T
. BOOLEAN . boolean . DECLARE . T
. assignmentStmt . . statements . NT
. ID . sum . ASSIGNOP . T
. ASSIGNOP . := . assignmentStmt . T
. RNUM . 0.0 . ASSIGNOP . T
. FOR . for . statements . T
. ID . index . FOR . T
. RANGEOP . .. . FOR . T
. NUM . 1 . RANGEOP . T
. NUM . 15 . RANGEOP . T
. DECLARE . declare . FOR . T
. idList . . DECLARE . NT
. ID . z0 . idList . T
. BOOLEAN . boolean . DECLARE . T
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . z . idList . T
. BOOLEAN . boolean . DECLARE . T
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . z2 . idList . T
. BOOLEAN . boolean . DECLARE . T
. PRINT . print . statements . T
. ID . sum . PRINT . T
. PROGRAM . program . T
. statements . . PROGRAM . NT
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . A . idList . T
. ARRAY . array . DECLARE . T
. NUM . 1 . ARRAY . T
. REAL . real . ARRAY . T
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . k . idList . T
. INTEGER . integer . DECLARE . T
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . s . idList . T
. REAL . real . DECLARE . T
. GET_VALUE . get_value . statements . T
. ID . k . GET_VALUE . T
. moduleReuseStmt . . statements . NT
. ASSIGNOP . . moduleReuseStmt . T
. ID . readArr . ASSIGNOP . T
. idList . . ASSIGNOP . NT
. ID . A . idList . T
. ID . k . idList . T
. moduleReuseStmt . . statements . NT
. idList . . ASSIGNOP . NT
. ID . s . idList . T
. ASSIGNOP . . moduleReuseStmt . T
. ID . arraySum . ASSIGNOP . T
. idList . . ASSIGNOP . NT
. ID . A . idList . T
. ID . k . idList . T
. PRINT . print . statements . T
. ID . s . PRINT . T
. otherModules . . NT
. MODULE . module . otherModules . T
. ID . readArr . MODULE . T
. input_plist . . MODULE . NT
. ID . arr1 . input_plist . T
. ARRAY . array . ID . T
. NUM . 1 . ARRAY . T
. REAL . real . ARRAY . T
. ID . k . input_plist . T
. INTEGER . integer . ID . T
. RETURNS . . MODULE . T
. statements . . MODULE . NT
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . tempvar . idList . T
. REAL . real . DECLARE . T
. DECLARE . declare . statements . T
. idList . . DECLARE . NT
. ID . i . idList . T
. INTEGER . integer . DECLARE . T
. assignmentStmt . . statements . NT
. ID . i . ASSIGNOP . T
. ASSIGNOP . := . assignmentStmt . T
. NUM . 1 . ASSIGNOP . T
. WHILE . while . statements . T
. ID . i . LE . T
. LE . <= . WHILE . T
. ID . k . LE . T
. GET_VALUE . get_value . WHILE . T
. ID . tempvar . GET_VALUE . T
. assignmentStmt . . WHILE . NT
. ID . arr1 . ASSIGNOP . T
. ID . i . ASSIGNOP . T
. ASSIGNOP . := . assignmentStmt . T
. ID . tempvar . ASSIGNOP . T
. assignmentStmt . . WHILE . NT
. ID . i . ASSIGNOP . T
. ASSIGNOP . := . assignmentStmt . T
. ID . i . PLUS . T
. PLUS . + . ASSIGNOP . T
. NUM . 1 . PLUS . T
**
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**
declare z0:boolean;
end
declare z:boolean;
declare z2:boolean;
print(sum);
end
<<<driver program>>>
start
declare i1,i2:integer;
declare A:array[i1..i2] of real;
declare B:array[3:11] of integer;
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
**
{
scope_0
for1(){
scope_1
for2(){
scope 1-1
}
for3(){
scope 1-2
}
}
for 4{}
}
**