commit c990953ff9d588de699e0a19420b5cc2d7e0db51
parent 7f4177cf55af62d6ed0d29db6bb545d640eba4ac
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 10 Jun 2012 09:58:54 +0200
Changing name of tokens
This names are shorter with the same clarity, so they are superior.
Diffstat:
M | decl.c | | | 4 | ++-- |
M | expr.c | | | 45 | ++++++++++++++++++++++----------------------- |
M | flow.c | | | 4 | ++-- |
M | lex.c | | | 36 | ++++++++++++++++++------------------ |
M | tokens.h | | | 13 | ++++++------- |
5 files changed, 50 insertions(+), 52 deletions(-)
diff --git a/decl.c b/decl.c
@@ -20,7 +20,7 @@ static void dirdcl(void)
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 @@ static struct type *specifier(void)
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'",
diff --git a/expr.c b/expr.c
@@ -12,11 +12,10 @@ void expr(void);
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 @@ static void postfix(void)
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 @@ static void unary(void)
return;
}
break;
- case INC_OP:
- case DEC_OP:
+ case INC:
+ case DEC:
next();
break;
case '&': case '*': case '-': case '~': case '!': case '+':
@@ -113,21 +112,21 @@ static void shift(void)
{
do
add();
- while (accept(LSHIFT_OP) || accept(RSHIFT_OP));
+ while (accept(LSHIFT) || accept(RSHIFT));
}
static void relational(void)
{
do
shift();
- while (accept('<') || accept('>') || accept(GE_OP) || accept(LE_OP));
+ while (accept('<') || accept('>') || accept(GE) || accept(LE));
}
static void equality(void)
{
do
relational();
- while (accept(EQ_OP) || accept(NE_OP));
+ while (accept(EQ) || accept(NE));
}
static void bit_and(void)
@@ -155,14 +154,14 @@ static void and(void)
{
do
bit_or();
- while (accept(AND_OP));
+ while (accept(AND));
}
static void or(void)
{
do
and();
- while (accept(OR_OP));
+ while (accept(OR));
}
static void conditional(void)
@@ -180,16 +179,16 @@ static void assign(void)
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;
diff --git a/flow.c b/flow.c
@@ -10,7 +10,7 @@ void stmt(void);
static void do_goto(void)
{
expect(GOTO);
- expect(IDENTIFIER);
+ expect(IDEN);
}
static void do_while(void)
@@ -102,7 +102,7 @@ void stmt(void)
case DEFAULT:
/* TODO */
break;
- case IDENTIFIER:
+ case IDEN:
/* TODO: check if it can be a label */
default:
expr();
diff --git a/lex.c b/lex.c
@@ -132,7 +132,7 @@ static unsigned char iden(void)
return kwp->tok;
}
yyval.sym = lookupsym(yytext, yyhash);
- return IDENTIFIER;
+ return IDEN;;
}
@@ -173,60 +173,60 @@ unsigned char next(void)
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:
diff --git a/tokens.h b/tokens.h
@@ -22,13 +22,12 @@ enum {
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
};