@@ -85,10 +85,7 @@ statement_list:
85
85
statement {*($$ .nextList) = *($1 .nextList);}
86
86
| statement_list marker_m statement
87
87
{
88
- cout<<" Backpacth statement List" <<endl;
89
- cout<< $2 .nextInstructionIndex << endl;
90
88
backpatch (*($1 .nextList) ,$2.nextInstructionIndex);
91
- cout<<" finish backpatch" <<endl;
92
89
*($$ .nextList) = *($3 .nextList);
93
90
}
94
91
;
@@ -111,9 +108,8 @@ marker_m:
111
108
112
109
marker_n :
113
110
%empty {
114
- cout<<" In marker n ==================== " << nextInstructionIndex<<" ======" <<endl;
115
111
// Save the index of the next instruction index in the marker
116
- $$ .nextList = new unordered_set<int >();
112
+ $$ .nextList = new unordered_set<int >();
117
113
*($$ .nextList) = makeList(nextInstructionIndex);
118
114
appendToCode (" goto _" );
119
115
}
138
134
' {' statement_list ' }'
139
135
marker_n
140
136
ELSE ' {' marker_m statement_list ' }' {
141
- cout<<" backpatching in if else" <<endl;
142
137
backpatch (*($3 .trueList), $5.nextInstructionIndex);
143
- cout<<" backpatching in if else" <<endl;
144
138
backpatch (*($3 .falseList), $12.nextInstructionIndex);
145
- cout<<" Finish backpatch if else" <<endl;
146
139
std::unordered_set<int > temp = mergeLists( *($7 .nextList), *($9 .nextList));
147
-
148
- cout<<" printing nextlist 9 =====================" <<endl;
149
- for (auto &&item:*($9 .nextList)) cout<<outputCode[item]<<endl;
150
-
151
140
$$ .nextList = new unordered_set<int >();
152
141
*($$ .nextList) = mergeLists(temp, *($13 .nextList));
153
142
}
@@ -156,20 +145,15 @@ if:
156
145
while :
157
146
WHILE marker_m ' (' boolean_expression ' )'
158
147
' {' marker_m statement_list ' }' {
159
- cout<<" backpatching in while" <<endl;
160
148
backpatch (*($8 .nextList), $2.nextInstructionIndex);
161
149
backpatch (*($4 .trueList), $7.nextInstructionIndex);
162
- cout<<" finish backpatch" <<endl;
163
- cout<<" next inst index ==== " <<nextInstructionIndex<<" " <<outputCode.size()<<endl;
164
- for (auto &&item:outputCode) cout<<item<<endl;
165
150
$$ .nextList = new unordered_set<int >();
166
151
*($$ .nextList) = *($4 .falseList);
167
152
appendToCode (" goto Label_" + to_string($2 .nextInstructionIndex));
168
153
}
169
154
;
170
155
171
156
assignment : IDENTIFIER ' =' expression ' ;' {
172
- cout<<" asg: " <<$1 <<" " <<" " <<$3 .varType<<endl;
173
157
if (checkIfVariableExists($1 )) {
174
158
// Check if the two sides have the same type
175
159
if (varToVarIndexAndType[$1 ].second == $3 .varType) {
@@ -232,24 +216,22 @@ boolean_expression:
232
216
$$ .trueList->insert (static_cast <int >(outputCode.size()));
233
217
$$ .falseList = new unordered_set<int >();
234
218
// write code goto line #
235
- appendToCode (" goto _" );
219
+ appendToCode (" goto _" );
236
220
}
237
221
| FALSE {
238
222
$$ .trueList = new unordered_set<int > ();
239
223
$$ .falseList= new unordered_set<int >();
240
224
$$ .falseList->insert (static_cast <int >(outputCode.size()));
241
225
// write code goto line #
242
- appendToCode (" goto _" );
226
+ appendToCode (" goto _" );
243
227
}
244
228
| boolean_expression BOOL_OP marker_m boolean_expression {
245
229
if (!strcmp($2 , " &&" )) {
246
- cout<<" backpatching bool" <<endl;
247
230
backpatch (*($1 .trueList), $3.nextInstructionIndex);
248
231
*($$ .trueList) = *($4 .trueList);
249
232
*($$ .falseList) = mergeLists(*($1 .falseList), *($4 .falseList));
250
233
}
251
234
else if (!strcmp($2 ," ||" )) {
252
- cout<<" backpatching in bool" <<endl;
253
235
backpatch (*($1 .falseList), $3.nextInstructionIndex);
254
236
*($$ .trueList) = mergeLists(*($1 .trueList), *($4 .trueList));
255
237
*($$ .falseList) = *($4 .falseList);
0 commit comments