X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=token.c;h=15cc4bbf668d29efa005d77f324ca1addac161cf;hb=cbfb5f3fbdbc786f6893a12dd636916278a2fd4e;hp=50e166a2caec59581b46b74d7517c7c4918565b4;hpb=d5e8df5885f97ea65839f8970b8697549c207610;p=cparser diff --git a/token.c b/token.c index 50e166a..15cc4bb 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); } } @@ -71,11 +84,14 @@ 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; default: - print_token_type(f, token->type); + print_token_type(f, (token_type_t)token->type); break; } }