-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cpp
More file actions
55 lines (45 loc) · 1.3 KB
/
Copy pathToken.cpp
File metadata and controls
55 lines (45 loc) · 1.3 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Token.hpp"
#include "ast/Number.hpp"
#include "ast/Operation.hpp"
#include "ast/Parenthesis.hpp"
#include "ast/Constant.hpp"
#include "ast/Variable.hpp"
#include "ast/PostfixOperation.hpp"
#include "ast/ASTNode.hpp"
Token::Token(const std::string &data, TokenType tokenType) : data(data), tokenType(tokenType) {}
const std::string &Token::getData() const {
return data;
}
TokenType Token::getTokenType() const {
return tokenType;
}
std::string Token::getType() const {
std::string typeStr;
switch (tokenType) {
case TokenType::NUMBER:
typeStr = "NUMBER";
break;
case TokenType::OPERATOR:
typeStr = "OPERATOR";
break;
case TokenType::PARENTHESIS_OPEN:
typeStr = "PARENTHESIS_OPEN";
break;
case TokenType::PARENTHESIS_CLOSE:
typeStr = "PARENTHESIS_CLOSE";
break;
case TokenType::CONSTANT:
typeStr = "CONSTANT";
break;
case TokenType::VARIABLE:
typeStr = "VARIABLE";
break;
case TokenType::POSTFIX_OPERATOR:
typeStr = "POSTFIX_OPERATOR";
break;
}
return typeStr;
}
std::string Token::toString() const {
return "{type:" + getType() + ", data:'" + data + "'}";
}