added the parsing of expression statements

This commit is contained in:
Karma Riuk
2025-07-08 09:51:15 +02:00
parent 08aacf0416
commit d13f9bf9f8
4 changed files with 47 additions and 8 deletions

View File

@@ -42,14 +42,6 @@ namespace parser {
}
}
bool parser::expect_next(token::type t) {
if (next.type == t) {
next_token();
return true;
}
next_error(t);
return false;
}
ast::expression* parser::parse_expression() {
// TODO: we are currently skipping expressions until we encounter a
// semicolon
@@ -85,7 +77,21 @@ namespace parser {
return stmt;
}
ast::expression_stmt* parser::parse_expression_stmt() {
ast::expression_stmt* stmt = new ast::expression_stmt(current);
stmt->expression = parse_expression();
return stmt;
};
bool parser::expect_next(token::type t) {
if (next.type == t) {
next_token();
return true;
}
next_error(t);
return false;
}
void parser::next_error(token::type t) {

View File

@@ -2,6 +2,7 @@
#include "ast/ast.hpp"
#include "ast/errors/error.hpp"
#include "ast/statements/expression.hpp"
#include "ast/statements/let.hpp"
#include "ast/statements/return.hpp"
#include "lexer/lexer.hpp"
@@ -24,6 +25,7 @@ namespace parser {
ast::expression* parse_expression();
ast::let_stmt* parse_let();
ast::return_stmt* parse_return();
ast::expression_stmt* parse_expression_stmt();
bool expect_next(token::type);
void next_error(token::type);
};