develop #5

Merged
cromer merged 14 commits from develop into master 2022-11-10 21:31:44 -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 "parser.h"
#include <memory>
obelisk::Parser::Parser()
{
lexer_ = new obelisk::Lexer();
lexer_ = std::unique_ptr<obelisk::Lexer> {new obelisk::Lexer()};
}
obelisk::Parser::Parser(obelisk::Lexer* lexer)
{
if (lexer != nullptr)
{
lexer_ = lexer;
}
else
{
Parser();
}
}
obelisk::Parser::~Parser()
{
delete lexer_;
}
obelisk::Lexer* obelisk::Parser::getLexer()
std::unique_ptr<obelisk::Lexer>& obelisk::Parser::getLexer()
{
return lexer_;
}
@ -91,7 +76,7 @@ std::unique_ptr<obelisk::ExpressionAST> obelisk::Parser::parseNumberExpression()
auto result = std::make_unique<obelisk::NumberExpressionAST>(
getLexer()->getNumberValue());
getNextToken();
return std::move(result);
return result;
}
std::unique_ptr<obelisk::ExpressionAST>

View File

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