scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit fec677da96689271e3be450a07961b56267f0afc
parent 0ece8c92df0019d3eb4d1d427f6001d18104e357
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  8 Feb 2012 19:29:29 +0100

Fixed correcct handling of yytext in all cases

We were handling correctly the identifier tokens, so this patch
fix this problem and copy the characters to yytext in the other cases

Diffstat:
Mlex.c | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lex.c b/lex.c @@ -58,7 +58,6 @@ static FILE *yyin; unsigned char yytoken; unsigned char yyhash; -size_t yylen; char yytext[TOKSIZ_MAX + 1]; unsigned linenum; unsigned columnum; @@ -108,7 +107,6 @@ static unsigned char iden(void) error("identifier too long %s", yytext); ungetc(ch, yyin); *bp = '\0'; - yylen = bp - yytext; yyhash &= NR_KWD_HASH - 1; for (kwp = khash[yyhash]; kwp; kwp = kwp->next) { if (!strcmp(kwp->str, yytext)) @@ -143,6 +141,8 @@ unsigned char gettok(void) switch (ch) { case '&': case '|': if ((c = getc(yyin)) == ch) { + yytext[1] = yytext[0] = ch; + yytext[2] = '\0'; ch |= 0x80; /* TODO */ break; } else { @@ -151,6 +151,9 @@ unsigned char gettok(void) case '^': case '=': case '<': case '>': case '*': case '+': case '-': case '/': if ((c = getc(yyin)) == '=') { + yytext[0] = ch; + yytext[1] = c; + yytext[2] = '\0'; ch |= 0x80; /* TODO */ break; } else { @@ -158,6 +161,8 @@ unsigned char gettok(void) } case ';': case '{': case '}': case '(': case ')': case '~': case '!': case ',': case '?': case '[': case ']': case ':': + yytext[0] = ch; + yytext[1] = '\0'; break; default: error("Incorrect character '%02x", c); @@ -165,7 +170,8 @@ unsigned char gettok(void) } return_token: - printf("Token = %c (%u)\n", (isprint(ch)) ? ch : ' ', (unsigned) ch); + printf("Token = %c (%u, '%s')\n", + (isprint(ch)) ? ch : ' ', (unsigned) ch, yytext); return yytoken = ch; }