written tests for infix expressions
This commit is contained in:
19
src/ast/expressions/infix.cpp
Normal file
19
src/ast/expressions/infix.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "infix.hpp"
|
||||
|
||||
#include "token/token.hpp"
|
||||
|
||||
namespace ast {
|
||||
|
||||
std::string infix_expr::token_literal() const {
|
||||
return token.literal;
|
||||
}
|
||||
|
||||
std::string infix_expr::str() const {
|
||||
return left->str() + token.literal + right->str();
|
||||
}
|
||||
|
||||
infix_expr::~infix_expr() {
|
||||
delete left;
|
||||
delete right;
|
||||
};
|
||||
} // namespace ast
|
17
src/ast/expressions/infix.hpp
Normal file
17
src/ast/expressions/infix.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "ast/ast.hpp"
|
||||
#include "token/token.hpp"
|
||||
|
||||
namespace ast {
|
||||
struct infix_expr : expression {
|
||||
token::token token;
|
||||
expression* left;
|
||||
std::string op;
|
||||
expression* right;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
~infix_expr();
|
||||
};
|
||||
} // namespace ast
|
Reference in New Issue
Block a user