-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_detector.hpp
More file actions
executable file
·32 lines (27 loc) · 990 Bytes
/
token_detector.hpp
File metadata and controls
executable file
·32 lines (27 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef MP_TOKEN_DETECTOR_HPP
#define MP_TOKEN_DETECTOR_HPP
#include "t_bracket.hpp"
#include "t_constant.hpp"
#include "t_function.hpp"
#include "t_number.hpp"
#include "t_operator.hpp"
#include "t_variable.hpp"
namespace mp
{
std::shared_ptr<Token> detect_token(const std::string &var)
{
TokenType tt{ Token::detect_tokenType(var) };
switch (tt)
{
case TokenType::NUMBER: return std::make_shared<Number>(var);
case TokenType::CONSTANT: return std::make_shared<Constant>(var);
case TokenType::VARIABLE: return std::make_shared<Variable>(var);
case TokenType::LEFT_BRACKET: return std::make_shared<LeftBracket>();
case TokenType::RIGHT_BRACKET: return std::make_shared<RightBracket>();
case TokenType::OPERATOR: return detect_operator(var);
case TokenType::FUNCTION: return detect_function(var);
default: throw std::invalid_argument("Error while detecting token, invalid syntax");
}
}
}
#endif // MP_TOKEN_DETECTOR_HPP