added return parsing

This commit is contained in:
Karma Riuk
2025-07-07 18:33:39 +02:00
parent 1638ddbfa1
commit 0b9d7d9c33
3 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
#include "return.hpp"
namespace ast {
return_stmt::return_stmt(token::token token)
: token(std::move(token)),
value(nullptr) {}
std::string return_stmt::token_literal() const {
return token.literal;
}
return_stmt::~return_stmt() {
delete value;
};
} // namespace ast

View File

@@ -0,0 +1,16 @@
#include "ast/ast.hpp"
#include "token/token.hpp"
namespace ast {
struct return_stmt : statement {
return_stmt(token::token token);
token::token token;
expression* value;
std::string token_literal() const override;
~return_stmt();
};
} // namespace ast

View File

@@ -51,6 +51,17 @@ namespace parser {
return false;
}
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()) {}
return stmt;
}
ast::let_stmt* parser::parse_let() {
ast::let_stmt* stmt = new ast::let_stmt(current);