shithub: scc

Download patch

ref: c990953ff9d588de699e0a19420b5cc2d7e0db51
parent: 7f4177cf55af62d6ed0d29db6bb545d640eba4ac
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jun 10 05:58:54 EDT 2012

Changing name of tokens

This names are shorter with the same clarity, so they are superior.

--- a/decl.c
+++ b/decl.c
@@ -20,7 +20,7 @@
 	if (accept('(')) {
 		declarator();
 		expect(')');
-	} else if (yytoken == IDENTIFIER) {
+	} else if (yytoken == IDEN) {
 		if (yyval.sym && yyval.sym->level == nested_level)
 			error("redeclaration of '%s'", yytext);
 		addsym(yytext, yyhash);
@@ -133,7 +133,7 @@
 				if (tqlf & T_RESTRICTED)  pushtype(RESTRICTED);
 				if (tqlf & T_VOLATILE)	  pushtype(VOLATILE);
 				return decl_type(t);
-			} else if (nested_level == 0 && yytoken == IDENTIFIER) {
+			} else if (nested_level == 0 && yytoken == IDEN) {
 				warning_error(user_opt.implicit_int,
 					      "type defaults to 'int' "
 					      "in declaration of '%s'",
--- a/expr.c
+++ b/expr.c
@@ -12,11 +12,10 @@
 static void primary(void)
 {
 	switch (yytoken) {
-	case IDENTIFIER:
+	case IDEN:
 		if (!yyval.sym)
 			error("'%s' undeclared", yytext);
 	case CONSTANT:
-	case STRING_LITERAL:
 		next();
 		break;
 	case '(':
@@ -43,12 +42,12 @@
 			expect(')');
 			break;
 		case '.':
-		case PTR_OP:
+		case PTR:
 			next();
-			expect(IDENTIFIER);
+			expect(IDEN);
 			break;
-		case INC_OP:
-		case DEC_OP:
+		case INC:
+		case DEC:
 			next();
 			break;
 		default:
@@ -71,8 +70,8 @@
 				return;
 			}
 			break;
-		case INC_OP:
-		case DEC_OP:
+		case INC:
+		case DEC:
 			next();
 			break;
 		case '&': case '*': case '-': case '~': case '!': case '+':
@@ -113,7 +112,7 @@
 {
 	do
 		add();
-	while (accept(LSHIFT_OP) || accept(RSHIFT_OP));
+	while (accept(LSHIFT) || accept(RSHIFT));
 }
 
 static void relational(void)
@@ -120,7 +119,7 @@
 {
 	do
 		shift();
-	while (accept('<') || accept('>') || accept(GE_OP) || accept(LE_OP));
+	while (accept('<') || accept('>') || accept(GE) || accept(LE));
 }
 
 static void equality(void)
@@ -127,7 +126,7 @@
 {
 	do
 		relational();
-	while (accept(EQ_OP) || accept(NE_OP));
+	while (accept(EQ) || accept(NE));
 }
 
 static void bit_and(void)
@@ -155,7 +154,7 @@
 {
 	do
 		bit_or();
-	while (accept(AND_OP));
+	while (accept(AND));
 }
 
 static void or(void)
@@ -162,7 +161,7 @@
 {
 	do
 		and();
-	while (accept(OR_OP));
+	while (accept(OR));
 }
 
 static void conditional(void)
@@ -180,16 +179,16 @@
 	unary();
 	switch (yytoken) {
 	case '=':
-	case MUL_ASSIGN:
-	case DIV_ASSIGN:
-	case MOD_ASSIGN:
-	case ADD_ASSIGN:
-	case SUB_ASSIGN:
-	case LSHIFT_ASSIGN:
-	case RSHIFT_ASSIGN:
-	case AND_ASSIGN:
-	case XOR_ASSIGN:
-	case OR_ASSIGN:
+	case MUL_EQ:
+	case DIV_EQ:
+	case MOD_EQ:
+	case ADD_EQ:
+	case SUB_EQ:
+	case LSHIFT_EQ:
+	case RSHIFT_EQ:
+	case AND_EQ:
+	case XOR_EQ:
+	case OR_EQ:
 		next();
 		assign();
 		break;
--- a/flow.c
+++ b/flow.c
@@ -10,7 +10,7 @@
 static void do_goto(void)
 {
 	expect(GOTO);
-	expect(IDENTIFIER);
+	expect(IDEN);
 }
 
 static void do_while(void)
@@ -102,7 +102,7 @@
 	case DEFAULT:
 		/* TODO */
 		break;
-	case IDENTIFIER:
+	case IDEN:
 		/* TODO: check if it can be a label */
 	default:
 		expr();
--- a/lex.c
+++ b/lex.c
@@ -132,7 +132,7 @@
 			return kwp->tok;
 	}
 	yyval.sym = lookupsym(yytext, yyhash);
-	return IDENTIFIER;
+	return IDEN;;
 }
 
 
@@ -173,60 +173,60 @@
 		switch (ch) {
 		case '&':
 			switch (aux) {
-			case '&': ch = AND_OP; break;
-			case '=': ch = AND_ASSIGN; break;
+			case '&': ch = AND; break;
+			case '=': ch = AND_EQ; break;
 			default:  goto no_doble_character;
 			}
 			break;
 		case '|':
 			switch (aux) {
-			case '|': ch = OR_OP; break;
-			case '=': ch = OR_ASSIGN; break;
+			case '|': ch = OR; break;
+			case '=': ch = OR_EQ; break;
 			default: goto no_doble_character;
 			}
 			break;
 		case '<':
 			switch (aux) {
-			case '<':  ch = LSHIFT_OP; break;
-			case '=':  ch = LSHIFT_ASSIGN; break;
+			case '<':  ch = LSHIFT; break;
+			case '=':  ch = LSHIFT_EQ; break;
 			default: goto no_doble_character;
 			}
 			break;
 		case '>':
 			switch (aux) {
-			case '<':  ch = RSHIFT_OP; break;
-			case '=':  ch = RSHIFT_ASSIGN; break;
+			case '<':  ch = RSHIFT; break;
+			case '=':  ch = RSHIFT_EQ; break;
 			default: goto no_doble_character;
 			}
 			break;
 		case '-':
 			switch (aux) {
-			case '-':  ch = DEC_OP; break;
-			case '>':  ch = PTR_OP; break;
-			case '=':  ch = ADD_ASSIGN; break;
+			case '-':  ch = DEC; break;
+			case '>':  ch = PTR; break;
+			case '=':  ch = SUB_EQ; break;
 			default: goto no_doble_character;
 			}
 			break;
 		case '=':
-			if (aux == '=') ch = EQ_OP;
+			if (aux == '=') ch = EQ;
 			else goto no_doble_character;
 			break;
 		case '^':
-			if (aux == '=') ch = XOR_ASSIGN;
+			if (aux == '=') ch = XOR_EQ;
 			else goto no_doble_character;
 			break;
 		case '*':
-			if (aux == '=') ch = LSHIFT_ASSIGN;
+			if (aux == '=') ch = LSHIFT_EQ;
 			else goto no_doble_character;
 			break;
 		case '+':
-			if (aux == '+')  ch = INC_OP;
-			else if (aux == '=') ch = ADD_ASSIGN;
+			if (aux == '+')  ch = INC;
+			else if (aux == '=') ch = ADD_EQ;
 			else goto no_doble_character;
 			break;
 		case '!':
 			if (aux == '=') {
-				ch = EQ_OP;
+				ch = NE;
 				break;
 			}
 		no_doble_character:
--- a/tokens.h
+++ b/tokens.h
@@ -22,13 +22,12 @@
 
 
 enum {
-	IDENTIFIER = 128, CONSTANT, STRING_LITERAL, SIZEOF,
-	PTR_OP, INC_OP, DEC_OP, LSHIFT_OP, RSHIFT_OP,
-	LE_OP, GE_OP, EQ_OP, NE_OP,
-	AND_OP, OR_OP, MUL_ASSIGN, DIV_ASSIGN, MOD_ASSIGN, ADD_ASSIGN,
-	SUB_ASSIGN, LSHIFT_ASSIGN, RSHIFT_ASSIGN, AND_ASSIGN,
-	XOR_ASSIGN, OR_ASSIGN, TYPE_NAME,
-	ELLIPSIS,
+	IDEN = 128, CONSTANT, SIZEOF,
+	PTR, INC, DEC, LSHIFT, RSHIFT,
+	LE, GE, EQ, NE, AND, OR,
+	MUL_EQ, DIV_EQ, MOD_EQ, ADD_EQ, SUB_EQ, AND_EQ,
+	XOR_EQ, OR_EQ, LSHIFT_EQ, RSHIFT_EQ,
+	TYPE_NAME, ELLIPSIS,
 	CASE, DEFAULT, IF, ELSE, SWITCH, WHILE, DO, FOR, GOTO,
 	CONTINUE, BREAK, RETURN, EOFTOK
 };