added string function to all nodes of ast
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "expression.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace ast {
|
||||
|
||||
expression_stmt::expression_stmt(token::token token)
|
||||
@@ -13,4 +15,13 @@ namespace ast {
|
||||
expression_stmt::~expression_stmt() {
|
||||
delete expression;
|
||||
}
|
||||
|
||||
std::string expression_stmt::str() const {
|
||||
std::stringstream ss;
|
||||
|
||||
if (expression != nullptr)
|
||||
ss << expression->str();
|
||||
|
||||
return ss.str();
|
||||
};
|
||||
} // namespace ast
|
||||
|
@@ -11,6 +11,7 @@ namespace ast {
|
||||
ast::expression* expression;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
|
||||
~expression_stmt();
|
||||
};
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include "let.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace ast {
|
||||
let_stmt::let_stmt(token::token token)
|
||||
: token(std::move(token)),
|
||||
@@ -14,4 +16,14 @@ namespace ast {
|
||||
delete name;
|
||||
delete value;
|
||||
};
|
||||
|
||||
std::string let_stmt::str() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << token_literal() << ' ' << name->str() << " = ";
|
||||
if (value != nullptr)
|
||||
ss << value->str();
|
||||
|
||||
return ss.str();
|
||||
};
|
||||
} // namespace ast
|
||||
|
@@ -13,6 +13,7 @@ namespace ast {
|
||||
expression* value;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
|
||||
~let_stmt();
|
||||
};
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include "return.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace ast {
|
||||
return_stmt::return_stmt(token::token token)
|
||||
: token(std::move(token)),
|
||||
@@ -12,4 +14,14 @@ namespace ast {
|
||||
return_stmt::~return_stmt() {
|
||||
delete value;
|
||||
};
|
||||
|
||||
std::string return_stmt::str() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << token_literal() << " ";
|
||||
if (value != nullptr)
|
||||
ss << value->str();
|
||||
|
||||
return ss.str();
|
||||
};
|
||||
} // namespace ast
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include "ast/ast.hpp"
|
||||
#include "token/token.hpp"
|
||||
@@ -10,6 +11,7 @@ namespace ast {
|
||||
expression* value;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
|
||||
~return_stmt();
|
||||
};
|
||||
|
Reference in New Issue
Block a user