shithub: scc

Download patch

ref: 427363d83864c086fbaf836bc412c451c87cc49d
parent: 69e7535d59c4e567c5279bea077e2ee7e24cb59a
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jun 5 16:16:27 EDT 2012

Added string names for tokens

This helps in order to can read the log traces.

--- a/lex.c
+++ b/lex.c
@@ -71,7 +71,75 @@
 	return h;
 }
 
+#ifndef NDEBUG
+static char *toknames[] = {
+	[INT] = "INT",
+	[CHAR] = "CHAR",
+	[FLOAT] = "FLOAT",
+	[LONG] = "LONG",
+	[LLONG] = "LLONG",
+	[SHORT] = "SHORT",
+	[VOID] = "VOID",
+	[DOUBLE] = "DOUBLE",
+	[LDOUBLE] = "LDOUBLE",
+	[STRUCT] = "STRUCT",
+	[UNION] = "UNION",
+	[ENUM] = "ENUM",
+	[UTYPE] = "UTYPE",
+	[BOOL] = "BOOL",
+	[TYPEDEF] = "TYPEDEF",
+	[EXTERN] = "EXTERN",
+	[STATIC] = "STATIC",
+	[AUTO] = "AUTO",
+	[REGISTER] = "REGISTER",
+	[VOLATILE] = "VOLATILE",
+	[CONST] = "CONST",
+	[RESTRICTED] = "RESTRICTED",
+	[UNSIGNED] = "UNSIGNED",
+	[SIGNED] = "SIGNED",
+	[IDENTIFIER] = "IDENTIFIER",
+	[CONSTANT] = "CONSTANT",
+	[STRING_LITERAL] = "STRING_LITERAL",
+	[SIZEOF] = "SIZEOF",
+	[PTR_OP] = "PTR_OP",
+	[INC_OP] = "INC_OP",
+	[DEC_OP] = "DEC_OP",
+	[LEFT_OP] = "LEFT_OP",
+	[RIGHT_OP] = "RIGHT_OP",
+	[LE_OP] = "LE_OP",
+	[GE_OP] = "GE_OP",
+	[EQ_OP] = "EQ_OP",
+	[NE_OP] = "NE_OP",
+	[AND_OP] = "AND_OP",
+	[OR_OP] = "OR_OP",
+	[MUL_ASSIGN] = "MUL_ASSIGN",
+	[DIV_ASSIGN] = "DIV_ASSIGN",
+	[MOD_ASSIGN] = "MOD_ASSIGN",
+	[ADD_ASSIGN] = "ADD_ASSIGN",
+	[SUB_ASSIGN] = "SUB_ASSIGN",
+	[LSHIFT_ASSIGN] = "LSHIFT_ASSIGN",
+	[RSHIFT_ASSIGN] = "RSHIFT_ASSIGN",
+	[AND_ASSIGN] = "AND_ASSIGN",
+	[XOR_ASSIGN] = "XOR_ASSIGN",
+	[OR_ASSIGN] = "OR_ASSIGN",
+	[TYPE_NAME] = "TYPE_NAME",
+	[ELLIPSIS] = "ELLIPSIS",
+	[CASE] = "CASE",
+	[DEFAULT] = "DEFAULT",
+	[IF] = "IF",
+	[ELSE] = "ELSE",
+	[SWITCH] = "SWITCH",
+	[WHILE] = "WHILE",
+	[DO] = "DO",
+	[FOR] = "FOR",
+	[GOTO] = "GOTO",
+	[CONTINUE] = "CONTINUE",
+	[BREAK] = "BREAK",
+	[RETURN] = "RETURN",
+	[EOFTOK] = "EOFTOK"
+};
 
+#endif
 
 void init_lex(void)
 {
@@ -191,8 +259,12 @@
 	}
 
 return_token:
-	printf("Token = %c (%u, '%s')\n",
-	       (isprint(ch)) ? ch : ' ', (unsigned) ch, yytext);
+#ifndef NDEBUG
+	printf(!toknames[ch] ?
+	       "Token = (%u, '%s')\n" :
+	       "Token = (%u, '%s' %s)\n",
+	       (unsigned) ch, yytext, toknames[ch]);
+#endif
 	return yytoken = ch;
 }