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

View File

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