fix for loops

This commit is contained in:
Wolfgang Bumiller 2015-01-20 20:55:27 +01:00
parent 5968e3faa0
commit 5c64437189
3 changed files with 24 additions and 2 deletions

View file

@ -2480,18 +2480,20 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
initexpr = parse_expression_leave(parser, false, false, false);
if (!initexpr)
goto onerr;
/* move on to condition */
if (parser->tok != ';') {
parseerror(parser, "expected semicolon after for-loop initializer");
goto onerr;
}
if (!parser_next(parser)) {
parseerror(parser, "expected for-loop condition");
goto onerr;
}
}
else if (!parser_next(parser)) {
parseerror(parser, "expected for-loop condition");
goto onerr;
}
/* parse the condition */
if (parser->tok != ';') {
@ -5685,6 +5687,8 @@ skipvar:
ast_delete(basetype);
for (auto &it : parser->gotos)
parseerror(parser, "undefined label: `%s`", it->name);
parser->gotos.clear();
parser->labels.clear();
return true;
} else {
ast_expression *cexp;

13
tests/forloop.qc Normal file
View file

@ -0,0 +1,13 @@
void main() {
float j;
for (j = 0; j < 2; ++j)
print("+");
for (float i = 0; i < 5; ++i)
print("*");
for (;;) {
print("\n");
break;
}
}

5
tests/forloop.tmpl Normal file
View file

@ -0,0 +1,5 @@
I: forloop.qc
D: test for loops
T: -execute
C: -std=gmqcc
M: ++*****