-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.h
121 lines (117 loc) · 2.29 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "uselib.h"
enum class token_type
{
Reserved_word,
Library_name,
Identifier,
Character,
Number,
Pointer,
Bracket,
Operator,
Comparator,
Address,
Punctuation,
Format_specifier,
Printed_token,
Comment,
Undefined_token,
Skipped_token,
NUL
};
std::string token_type_toString(token_type type)
{
switch (type)
{
case token_type::Reserved_word:
return "reserved word";
break;
case token_type::Library_name:
return "library name";
break;
case token_type::Identifier:
return "identifier";
break;
case token_type::Character:
return "character";
break;
case token_type::Number:
return "number";
break;
case token_type::Pointer:
return "pointer";
break;
case token_type::Bracket:
return "bracket";
break;
case token_type::Operator:
return "operator";
break;
case token_type::Comparator:
return "comparator";
break;
case token_type::Address:
return "address";
break;
case token_type::Punctuation:
return "punctuation";
break;
case token_type::Format_specifier:
return "format specifier";
break;
case token_type::Printed_token:
return "printed token";
break;
case token_type::Comment:
return "comment";
break;
case token_type::Undefined_token:
return "undefined token";
break;
case token_type::Skipped_token:
return "skipped token";
break;
case token_type::NUL:
return "NUL";
break;
default:
return "error";
break;
}
}
class Token
{
private:
token_type type;
std::string text;
public:
Token();
Token(char, token_type);
Token(std::string, token_type);
std::string getText();
token_type getType();
~Token(){};
};
Token::Token()
{
this->type = token_type::NUL;
this->text = '$';
}
Token::Token(char c, token_type type)
{
this->type = type;
this->text = c;
}
Token::Token(std::string str, token_type type)
{
this->type = type;
this->text = str;
}
std::string Token::getText()
{
return this->text;
}
token_type Token::getType()
{
return this->type;
}