11 static symbol_t *token_symbols[T_LAST_TOKEN];
13 void init_tokens(void)
17 memset(token_symbols, 0, T_LAST_TOKEN * sizeof(token_symbols[0]));
19 #define T(x,str,val) \
20 assert(T_##x >= 0 && T_##x < T_LAST_TOKEN); \
21 symbol = symbol_table_insert(str); \
23 token_symbols[T_##x] = symbol;
25 #define TS(x,str,val) \
26 assert(T_##x >= 0 && T_##x < T_LAST_TOKEN); \
27 symbol = symbol_table_insert(str); \
28 token_symbols[T_##x] = symbol;
35 #define T(x,str,val) \
36 assert(TP_##x >= 0 && TP_##x < TP_LAST_TOKEN); \
37 symbol = symbol_table_insert(str); \
38 symbol->pp_ID = TP_##x;
40 #include "tokens_preprocessor.inc"
45 void exit_tokens(void)
49 void print_token_type(FILE *f, token_type_t token_type)
51 if(token_type == T_EOF) {
52 fputs("end of file", f);
55 if(token_type == T_ERROR) {
60 int token_symbols_len = T_LAST_TOKEN;
61 if(token_type < 0 || token_type >= token_symbols_len) {
62 fputs("invalid token", f);
66 const symbol_t *symbol = token_symbols[token_type];
68 fprintf(f, "'%s'", symbol->string);
70 if(token_type >= 0 && token_type < 256) {
71 fprintf(f, "'%c'", token_type);
74 fputs("unknown token", f);
78 void print_token(FILE *f, const token_t *token)
82 fprintf(f, "symbol '%s'", token->v.symbol->string);
85 fprintf(f, "integer number %d", token->v.intvalue);
87 case T_STRING_LITERAL:
88 fprintf(f, "string '%s'", token->v.string);
91 print_token_type(f, token->type);