optimize the parser code
This commit is contained in:
parent
6592f208d9
commit
257df0fc99
@ -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>
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user