Add null statement

This commit is contained in:
Rui Ueyama 2020-05-14 11:05:01 +09:00
parent 18ac283a5d
commit ff8912c68e
2 changed files with 7 additions and 1 deletions

View File

@ -91,8 +91,13 @@ static Node *compound_stmt(Token **rest, Token *tok) {
return node;
}
// expr-stmt = expr ";"
// expr-stmt = expr? ";"
static Node *expr_stmt(Token **rest, Token *tok) {
if (equal(tok, ";")) {
*rest = tok->next;
return new_node(ND_BLOCK);
}
Node *node = new_unary(ND_EXPR_STMT, expr(&tok, tok));
*rest = skip(tok, ";");
return node;

View File

@ -60,5 +60,6 @@ assert 2 '{ 1; return 2; 3; }'
assert 3 '{ 1; 2; return 3; }'
assert 3 '{ {1; {2;} return 3;} }'
assert 5 '{ ;;; return 5; }'
echo OK