added parsing of if statements
This commit is contained in:
25
src/ast/statements/block.cpp
Normal file
25
src/ast/statements/block.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "block.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace ast {
|
||||
block_stmt::block_stmt(token::token token): token(std::move(token)) {}
|
||||
|
||||
std::string block_stmt::token_literal() const {
|
||||
return token.literal;
|
||||
}
|
||||
|
||||
block_stmt::~block_stmt() {
|
||||
for (const auto& stmt : statements)
|
||||
delete stmt;
|
||||
};
|
||||
|
||||
std::string block_stmt::str() const {
|
||||
std::stringstream ss;
|
||||
ss << "{";
|
||||
for (const auto& stmt : statements)
|
||||
ss << stmt->str();
|
||||
ss << "}";
|
||||
return ss.str();
|
||||
};
|
||||
} // namespace ast
|
20
src/ast/statements/block.hpp
Normal file
20
src/ast/statements/block.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "ast/ast.hpp"
|
||||
#include "token/token.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ast {
|
||||
struct block_stmt : statement {
|
||||
block_stmt(token::token token);
|
||||
|
||||
token::token token;
|
||||
std::vector<ast::statement*> statements;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
|
||||
~block_stmt();
|
||||
};
|
||||
} // namespace ast
|
Reference in New Issue
Block a user