#include "tokens.inc"
#undef TS
+#undef T
+
+#define T(x,str,val) \
+ assert(TP_##x >= 0 && TP_##x < TP_LAST_TOKEN); \
+ symbol = symbol_table_insert(str); \
+ symbol->pp_ID = TP_##x;
+
+#include "tokens_preprocessor.inc"
+
#undef T
}
void print_token_type(FILE *f, token_type_t token_type)
{
- if(token_type >= 0 && token_type < 256) {
- fprintf(f, "'%c'", token_type);
- return;
- }
if(token_type == T_EOF) {
fputs("end of file", f);
return;
}
+ if(token_type == T_ERROR) {
+ fputs("error", f);
+ return;
+ }
int token_symbols_len = T_LAST_TOKEN;
if(token_type < 0 || token_type >= token_symbols_len) {
const symbol_t *symbol = token_symbols[token_type];
if(symbol != NULL) {
- fputs(symbol->string, f);
+ fprintf(f, "'%s'", symbol->string);
} else {
+ if(token_type >= 0 && token_type < 256) {
+ fprintf(f, "'%c'", token_type);
+ return;
+ }
fputs("unknown token", f);
}
}
case T_INTEGER:
fprintf(f, "integer number %d", token->v.intvalue);
break;
+ case T_FLOATINGPOINT:
+ fprintf(f, "floatingpointer number %f", token->v.floatvalue);
+ break;
case T_STRING_LITERAL:
fprintf(f, "string '%s'", token->v.string);
break;