-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.c
More file actions
47 lines (37 loc) · 1.18 KB
/
Copy pathtoken.c
File metadata and controls
47 lines (37 loc) · 1.18 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
#include "compiler.h"
#define PRIMITIVE_TYPES_TOTAL 7
const char *primitive_types[PRIMITIVE_TYPES_TOTAL] = {
"void", "char", "short", "int", "long", "float", "double"
};
bool token_is_identifier(struct token *token) {
return token && token->type == TOKEN_TYPE_IDENTIFIER;
}
bool token_is_symbol(struct token *token, char c) {
return token->type == TOKEN_TYPE_SYMBOL && token->cval == c;
}
bool token_is_operator(struct token *token, const char *val) {
return token && token->type == TOKEN_TYPE_OPERATOR && S_EQ(token->sval, val);
}
bool token_is_nl_or_comment_or_newline_seperator(struct token *token) {
if (!token)
return false;
return token->type == TOKEN_TYPE_NEWLINE || token->type == TOKEN_TYPE_COMMENT
|| token_is_symbol(token, '\\');
}
bool token_is_keyword(struct token *token, const char *value) {
return token && token->type == TOKEN_TYPE_KEYWORD && S_EQ(token->sval, value);
}
bool token_is_primitive_keyword(struct token *token) {
if (!token) {
return false;
}
if (token->type != TOKEN_TYPE_KEYWORD) {
return false;
}
for (int i = 0; i < PRIMITIVE_TYPES_TOTAL; i++) {
if (S_EQ(primitive_types[i], token->sval)) {
return true;
}
}
return false;
}