-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cpp
More file actions
44 lines (41 loc) · 854 Bytes
/
Copy pathToken.cpp
File metadata and controls
44 lines (41 loc) · 854 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
33
34
35
36
37
38
39
40
41
42
43
44
#include "Token.h"
#include <cstdio>
Token::Token() {
name = INVALID;
attrib = 0;
line = 1;
column = 1;
}
Token::Token(int name_, int attrib_, size_t line_, size_t column_) {
name = name_;
attrib = attrib_;
line = line_;
column = column_;
}
std::string Token::name_str() const {
switch (name) {
case INVALID:
return "ERROR";
case ID:
return "id";
case RELOP:
return "relop";
case NUMBER:
return "number";
case STRING:
return "string";
case CONCAT:
return "..";
case EOTS:
return "EOTS";
default:
// keyword
if (KW_ENUM_BEGIN < name && name < KW_ENUM_END) {
return KEYWORDS[attrib];
}
// tokens that are a single ascii character
// this is for the program not to display a mess if compiled with msvc
char temp[2] = { (char)name, '\0' };
return temp;
}
}