the 'local' keyword now also introduces the declaration of a local variable

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-14 16:22:38 +02:00
parent 5064554b76
commit 2d9623cbe8

View file

@ -1244,7 +1244,22 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
}
else if (parser->tok == TOKEN_KEYWORD)
{
if (!strcmp(parser_tokval(parser), "return"))
if (!strcmp(parser_tokval(parser), "local"))
{
if (!block) {
parseerror(parser, "cannot declare a local variable here");
return false;
}
if (!parser_next(parser)) {
parseerror(parser, "expected variable declaration");
return false;
}
if (!parser_variable(parser, block))
return false;
*out = NULL;
return true;
}
else if (!strcmp(parser_tokval(parser), "return"))
{
ast_expression *exp = NULL;
ast_return *ret = NULL;