shithub: scc

Download patch

ref: fec677da96689271e3be450a07961b56267f0afc
parent: 0ece8c92df0019d3eb4d1d427f6001d18104e357
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Feb 8 14:29:29 EST 2012

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

--- a/lex.c
+++ b/lex.c
@@ -58,7 +58,6 @@
 
 unsigned char yytoken;
 unsigned char yyhash;
-size_t yylen;
 char yytext[TOKSIZ_MAX + 1];
 unsigned linenum;
 unsigned columnum;
@@ -108,7 +107,6 @@
 		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 @@
 		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 @@
 		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 @@
 			}
 		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 @@
 	}
 
 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;
 }