extracted the parsing of the "expressions" to it's

own function so we can just modify that once we
get there
This commit is contained in:
Karma Riuk
2025-07-08 09:50:41 +02:00
parent 0b9d7d9c33
commit 08aacf0416
2 changed files with 12 additions and 6 deletions

View File

@@ -50,14 +50,18 @@ namespace parser {
next_error(t);
return false;
}
ast::expression* parser::parse_expression() {
// TODO: we are currently skipping expressions until we encounter a
// semicolon
for (; current.type != token::type::SEMICOLON; next_token()) {}
return nullptr;
};
ast::return_stmt* parser::parse_return() {
ast::return_stmt* stmt = new ast::return_stmt(current);
next_token();
// TODO: we are currently skipping expressions until we encounter a
// semicolon
for (; current.type != token::type::SEMICOLON; next_token()) {}
stmt->value = parse_expression();
return stmt;
}
@@ -77,9 +81,10 @@ namespace parser {
return nullptr;
}
// TODO: we are currently skipping expressions until we encounter a
// semicolon
for (; current.type != token::type::SEMICOLON; next_token()) {}
stmt->value = parse_expression();
return stmt;
}
return stmt;
}

View File

@@ -21,6 +21,7 @@ namespace parser {
void next_token();
ast::statement* parse_statement();
ast::expression* parse_expression();
ast::let_stmt* parse_let();
ast::return_stmt* parse_return();
bool expect_next(token::type);