added return parsing
This commit is contained in:
15
src/ast/statements/return.cpp
Normal file
15
src/ast/statements/return.cpp
Normal 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
|
16
src/ast/statements/return.hpp
Normal file
16
src/ast/statements/return.hpp
Normal 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
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user