-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.h
69 lines (63 loc) · 1.74 KB
/
Token.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef TOKEN_H
#define TOKEN_H
#include <string>
#include <sstream>
#include <iostream>
typedef enum {UNDEFINED = -1,COMMA,PERIOD,Q_MARK,LEFT_PAREN,RIGHT_PAREN,COLON,COLON_DASH,MULTIPLY,ADD,
SCHEMES,FACTS,RULES,QUERIES,ID,COMMENT,STRING,WHITESPACE,END_FILE} macType;
class Token {
private:
std::string data;
std::string error;
int line;
int type;
public:
friend class Parser;
Token (int type, std::string data, int line) {
this->line = line;
this->type = type;
this->data = data;
this->error = "";
}
Token* addError(std::string error) {
this->error = error;
return this;
}
int getType() const {
return type;
}
int getLine() const {
return line;
}
std::string getData() const {
return data;
}
std::string toString() {
std::stringstream ss;
ss << "(";
switch (type) {
case UNDEFINED: ss << "UNDEFINED"; break;
case COMMA: ss << "COMMA"; break;
case PERIOD: ss << "PERIOD"; break;
case Q_MARK: ss << "Q_MARK"; break;
case LEFT_PAREN: ss << "LEFT_PAREN"; break;
case RIGHT_PAREN: ss << "RIGHT_PAREN"; break;
case COLON: ss << "COLON"; break;
case COLON_DASH: ss << "COLON_DASH"; break;
case MULTIPLY: ss << "MULTIPLY"; break;
case ADD: ss << "ADD"; break;
case SCHEMES: ss << "SCHEMES"; break;
case FACTS: ss << "FACTS"; break;
case RULES: ss << "RULES"; break;
case QUERIES: ss << "QUERIES"; break;
case ID: ss << "ID"; break;
case COMMENT: ss << "COMMENT"; break;
case STRING: ss << "STRING"; break;
case END_FILE: ss << "EOF"; break;
case WHITESPACE:return ""; break;
}
ss << ",\"" << data << "\"," << line << ")" << std::endl;
return ss.str();
}
};
#endif