parser.cxx

changeset 45
e1d3b7ea975c
parent 44
6bbaebc472b5
child 46
a29eeecf3ecb
equal deleted inserted replaced
44:6bbaebc472b5 45:e1d3b7ea975c
185 if (FindCommand (token)) 185 if (FindCommand (token))
186 ParserError ("label name `%s` conflicts with command name\n", token.chars()); 186 ParserError ("label name `%s` conflicts with command name\n", token.chars());
187 if (FindGlobalVariable (token)) 187 if (FindGlobalVariable (token))
188 ParserError ("label name `%s` conflicts with variable\n", token.chars()); 188 ParserError ("label name `%s` conflicts with variable\n", token.chars());
189 189
190 w->AddMark (MARKTYPE_LABEL, token); 190 w->AddMark (token);
191 MustNext (":"); 191 MustNext (":");
192 continue; 192 continue;
193 } 193 }
194 194
195 // ============================================================ 195 // ============================================================
199 199
200 // Get the name of the label 200 // Get the name of the label
201 MustNext (); 201 MustNext ();
202 202
203 // Find the mark this goto statement points to 203 // Find the mark this goto statement points to
204 unsigned int m = w->FindMark (MARKTYPE_LABEL, token); 204 unsigned int m = w->FindMark (token);
205 if (m == MAX_MARKS) 205 if (m == MAX_MARKS)
206 ParserError ("unknown label `%s`!", token.chars()); 206 ParserError ("unknown label `%s`!", token.chars());
207 207
208 // Add a reference to the mark. 208 // Add a reference to the mark.
209 w->Write<word> (DH_GOTO); 209 w->Write<word> (DH_GOTO);
229 MustNext (")"); 229 MustNext (")");
230 MustNext ("{"); 230 MustNext ("{");
231 231
232 // Add a mark - to here temporarily - and add a reference to it. 232 // Add a mark - to here temporarily - and add a reference to it.
233 // Upon a closing brace, the mark will be adjusted. 233 // Upon a closing brace, the mark will be adjusted.
234 unsigned int marknum = w->AddMark (MARKTYPE_IF, ""); 234 unsigned int marknum = w->AddMark ("");
235 235
236 // Use DH_IFNOTGOTO - if the expression is not true, we goto the mark 236 // Use DH_IFNOTGOTO - if the expression is not true, we goto the mark
237 // we just defined - and this mark will be at the end of the block. 237 // we just defined - and this mark will be at the end of the block.
238 w->Write<word> (DH_IFNOTGOTO); 238 w->Write<word> (DH_IFNOTGOTO);
239 w->AddReference (marknum); 239 w->AddReference (marknum);
252 252
253 // While loops need two marks - one at the start of the loop and one at the 253 // While loops need two marks - one at the start of the loop and one at the
254 // end. The condition is checked at the very start of the loop, if it fails, 254 // end. The condition is checked at the very start of the loop, if it fails,
255 // we use goto to skip to the end of the loop. At the end, we loop back to 255 // we use goto to skip to the end of the loop. At the end, we loop back to
256 // the beginning with a go-to statement. 256 // the beginning with a go-to statement.
257 unsigned int mark1 = w->AddMark (MARKTYPE_INTERNAL, ""); // start 257 unsigned int mark1 = w->AddMark (""); // start
258 unsigned int mark2 = w->AddMark (MARKTYPE_INTERNAL, ""); // end 258 unsigned int mark2 = w->AddMark (""); // end
259 259
260 // Condition 260 // Condition
261 MustNext ("("); 261 MustNext ("(");
262 MustNext (); 262 MustNext ();
263 DataBuffer* expr = ParseExpression (TYPE_INT); 263 DataBuffer* expr = ParseExpression (TYPE_INT);
304 304
305 // First, write out the initializer 305 // First, write out the initializer
306 w->WriteBuffer (init); 306 w->WriteBuffer (init);
307 307
308 // Init two marks 308 // Init two marks
309 int mark1 = w->AddMark (MARKTYPE_INTERNAL, ""); 309 int mark1 = w->AddMark ("");
310 int mark2 = w->AddMark (MARKTYPE_INTERNAL, ""); 310 int mark2 = w->AddMark ("");
311 311
312 // Add the condition 312 // Add the condition
313 w->WriteBuffer (cond); 313 w->WriteBuffer (cond);
314 w->Write<long> (DH_IFNOTGOTO); 314 w->Write<long> (DH_IFNOTGOTO);
315 w->AddReference (mark2); 315 w->AddReference (mark2);
328 MUST_NOT_TOPLEVEL 328 MUST_NOT_TOPLEVEL
329 PushBlockStack (); 329 PushBlockStack ();
330 MustNext ("{"); 330 MustNext ("{");
331 331
332 // Store the marks and incrementor 332 // Store the marks and incrementor
333 blockstack[g_BlockStackCursor].mark1 = w->AddMark (MARKTYPE_INTERNAL, ""); 333 blockstack[g_BlockStackCursor].mark1 = w->AddMark ("");
334 blockstack[g_BlockStackCursor].type = BLOCKTYPE_DO; 334 blockstack[g_BlockStackCursor].type = BLOCKTYPE_DO;
335 continue; 335 continue;
336 } 336 }
337 337
338 // ============================================================ 338 // ============================================================

mercurial