X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=token.c;h=1496f353e68175f69ea0ed18663c0ed478b406cf;hb=619e8bbd734140dd6562c9f10c43c029eaa3f52d;hp=50e166a2caec59581b46b74d7517c7c4918565b4;hpb=d5e8df5885f97ea65839f8970b8697549c207610;p=cparser diff --git a/token.c b/token.c index 50e166a..1496f35 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,14 +48,14 @@ 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; } + 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) { @@ -56,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); } }