feature/knowledge_base #3

Merged
cromer merged 9 commits from feature/knowledge_base into develop 2022-11-09 16:52:23 -03:00
2 changed files with 7 additions and 24 deletions
Showing only changes of commit 257df0fc99 - Show all commits

View File

@ -3,29 +3,14 @@
#include "ast/variable_expression_ast.h" #include "ast/variable_expression_ast.h"
#include "parser.h" #include "parser.h"
#include <memory>
obelisk::Parser::Parser() obelisk::Parser::Parser()
{ {
lexer_ = new obelisk::Lexer(); lexer_ = std::unique_ptr<obelisk::Lexer> {new obelisk::Lexer()};
} }
obelisk::Parser::Parser(obelisk::Lexer* lexer) std::unique_ptr<obelisk::Lexer>& obelisk::Parser::getLexer()
{
if (lexer != nullptr)
{
lexer_ = lexer;
}
else
{
Parser();
}
}
obelisk::Parser::~Parser()
{
delete lexer_;
}
obelisk::Lexer* obelisk::Parser::getLexer()
{ {
return lexer_; return lexer_;
} }
@ -91,7 +76,7 @@ std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parseNumberExpression()
auto result = std::make_unique<obelisk::NumberExpressionAST>( auto result = std::make_unique<obelisk::NumberExpressionAST>(
getLexer()->getNumberValue()); getLexer()->getNumberValue());
getNextToken(); getNextToken();
return std::move(result); return result;
} }
std::unique_ptr<obelisk::ExpressionAST> std::unique_ptr<obelisk::ExpressionAST>

View File

@ -13,7 +13,7 @@ namespace obelisk
class Parser class Parser
{ {
private: private:
obelisk::Lexer* lexer_; std::unique_ptr<obelisk::Lexer> lexer_;
int currentToken_; int currentToken_;
void setCurrentToken(int currentToken); void setCurrentToken(int currentToken);
@ -35,10 +35,8 @@ namespace obelisk
public: public:
Parser(); Parser();
Parser(obelisk::Lexer* lexer);
~Parser();
obelisk::Lexer* getLexer(); std::unique_ptr<obelisk::Lexer>& getLexer();
int getCurrentToken(); int getCurrentToken();