-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cpp
More file actions
54 lines (47 loc) · 1.75 KB
/
Token.cpp
File metadata and controls
54 lines (47 loc) · 1.75 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
54
#include "Token.h"
#include <string>
#include <iostream>
Token::Token(TokenType type, std::string description, int line) {
this->token = type;
this->description = description;
this->startLine = line;
}
Token::Token(TokenType type, char description, int line) {
this->token = type;
this->description = description;
this->startLine = line;
}
string Token::tokenToString(TokenType token) {
switch(token) {
case TokenType::COLON: return "COLON"; break;
case TokenType::COLON_DASH: return "COLON_DASH"; break;
case TokenType::COMMA: return "COMMA"; break;
case TokenType::PERIOD: return "PERIOD"; break;
case TokenType::Q_MARK: return "Q_MARK"; break;
case TokenType::LEFT_PAREN: return "LEFT_PAREN"; break;
case TokenType::RIGHT_PAREN: return "RIGHT_PAREN"; break;
case TokenType::MULTIPLY: return "MULTIPLY"; break;
case TokenType::ADD: return "ADD"; break;
case TokenType::SCHEMES: return "SCHEMES"; break;
case TokenType::FACTS: return "FACTS"; break;
case TokenType::RULES: return "RULES"; break;
case TokenType::QUERIES: return "QUERIES"; break;
case TokenType::ID: return "ID"; break;
case TokenType::STRING: return "STRING"; break;
case TokenType::COMMENT: return "COMMENT"; break;
case TokenType::UNDEFINED: return "UNDEFINED"; break;
case TokenType::END: return "EOF"; break;
}
return "";
}
string Token::toString() {
string tokenString;
tokenString = "(" + tokenToString(token) + ",\"" + description + "\"," + to_string(startLine) + ")";
return tokenString;
}
TokenType Token::getTokenType() {
return this->token;
}
string Token::getDescription() {
return this->description;
}