11 static symbol_t *token_symbols[T_LAST_TOKEN];
13 source_position_t builtin_source_position = { "<built-in>", 0 };
15 void init_tokens(void)
19 memset(token_symbols, 0, T_LAST_TOKEN * sizeof(token_symbols[0]));
21 #define T(x,str,val) \
22 assert(T_##x >= 0 && T_##x < T_LAST_TOKEN); \
23 symbol = symbol_table_insert(str); \
25 token_symbols[T_##x] = symbol;
27 #define TS(x,str,val) \
28 assert(T_##x >= 0 && T_##x < T_LAST_TOKEN); \
29 symbol = symbol_table_insert(str); \
30 token_symbols[T_##x] = symbol;
37 #define T(x,str,val) \
38 assert(TP_##x >= 0 && TP_##x < TP_LAST_TOKEN); \
39 symbol = symbol_table_insert(str); \
40 symbol->pp_ID = TP_##x;
42 #include "tokens_preprocessor.inc"
47 void exit_tokens(void)
51 void print_token_type(FILE *f, token_type_t token_type)
53 if(token_type == T_EOF) {
54 fputs("end of file", f);
57 if(token_type == T_ERROR) {
62 int token_symbols_len = T_LAST_TOKEN;
63 if(token_type < 0 || token_type >= token_symbols_len) {
64 fputs("invalid token", f);
68 const symbol_t *symbol = token_symbols[token_type];
70 fprintf(f, "'%s'", symbol->string);
72 if(token_type >= 0 && token_type < 256) {
73 fprintf(f, "'%c'", token_type);
76 fputs("unknown token", f);
80 void print_token(FILE *f, const token_t *token)
84 fprintf(f, "symbol '%s'", token->v.symbol->string);
87 fprintf(f, "integer number %lld", token->v.intvalue);
90 fprintf(f, "floatingpointer number %LF", token->v.floatvalue);
92 case T_STRING_LITERAL:
93 fprintf(f, "string '%s'", token->v.string);
96 print_token_type(f, (token_type_t)token->type);