X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=token.c;h=4769365843bc98ae6c8eef1509f244aca63cdcc5;hb=af75875e8faedae0deb5571f503a9c0f521ff298;hp=eaa1deca87956a297733ff7e05f0ffb8dc6ab2db;hpb=fbad4d6c6c4f43d7ae379d1ff48c1c1c21768edf;p=cparser diff --git a/token.c b/token.c index eaa1dec..4769365 100644 --- a/token.c +++ b/token.c @@ -30,6 +30,15 @@ void init_tokens(void) #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 } @@ -39,10 +48,6 @@ void exit_tokens(void) 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; @@ -60,8 +65,12 @@ void print_token_type(FILE *f, token_type_t token_type) 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); } } @@ -75,6 +84,9 @@ void print_token(FILE *f, const token_t *token) 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;