X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=lexer.c;h=699f8ee5cdd224e89970214bc27c9542ea68c4d4;hb=4b01aba61ad8d1c130517ae7bb51eea9b22e9a44;hp=9fa306dc80ca50b7017d061e1663614941b42022;hpb=16960178ce1714e96fe33cb1ff54ce377cb05dca;p=cparser diff --git a/lexer.c b/lexer.c index 9fa306d..699f8ee 100644 --- a/lexer.c +++ b/lexer.c @@ -22,6 +22,17 @@ #define strtold(s, e) strtod(s, e) #endif +#define HAS_SIGNED_CHAR +//#define HAS_UNSIGNED_CHAR + +#if defined HAS_SIGNED_CHAR +typedef signed char char_type; +#elif defined HAS_UNSIGNED_CHAR +typedef unsigned char char_type; +#else +# error signedness of char not determined +#endif + static int c; token_t lexer_token; symbol_t *symbol_L; @@ -336,7 +347,7 @@ static unsigned long long parse_int_string(const char *s, const char **endptr, i case 16: for (;; ++s) { /* check for overrun */ - if (v <= 0x1000000000000000ULL) + if (v >= 0x1000000000000000ULL) break; switch (tolower(*s)) { case '0': v <<= 4; break; @@ -363,7 +374,7 @@ static unsigned long long parse_int_string(const char *s, const char **endptr, i case 8: for (;; ++s) { /* check for overrun */ - if (v <= 0x2000000000000000ULL) + if (v >= 0x2000000000000000ULL) break; switch (tolower(*s)) { case '0': v <<= 3; break; @@ -503,8 +514,8 @@ static void parse_number_dec(void) obstack_1grow(&symbol_obstack, '\0'); char *string = obstack_finish(&symbol_obstack); - const char *endptr; if(is_float) { + char *endptr; lexer_token.type = T_FLOATINGPOINT; lexer_token.v.floatvalue = strtold(string, &endptr); @@ -514,6 +525,7 @@ static void parse_number_dec(void) parse_floating_suffix(); } else { + const char *endptr; lexer_token.type = T_INTEGER; lexer_token.v.intvalue = parse_int_string(string, &endptr, 10); @@ -574,7 +586,7 @@ static int parse_octal_sequence(const int first_digit) if (!is_octal_digit(c)) return value; value = 8 * value + c - '0'; next_char(); - return value; + return (char_type)value; } static int parse_hex_sequence(void) @@ -593,7 +605,7 @@ static int parse_hex_sequence(void) next_char(); } - return value; + return (char_type)value; } static int parse_escape_sequence(void)