scc

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

commit dd9d39f1f5a09924ab111b97e64d144075d898cd
parent aabab2cdfb2cd0dc24ad55e4fff5d7f7ccd0de03
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  9 Mar 2014 16:51:42 +0100

Use TYPE for struct, enum and unions

Diffstat:
Mdecl.c | 20+++++++++-----------
Mlex.c | 6+++---
2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/decl.c b/decl.c @@ -176,6 +176,8 @@ bool specifier(register struct ctype *tp, struct storage *store, struct qualifier *qlf) { + unsigned char tok; + for (;; next()) { switch (yytoken) { case TQUALIFIER: @@ -185,18 +187,14 @@ specifier(register struct ctype *tp, store = storage(store, yyval->c); break; case TYPE: - tp = ctype(tp, yyval->c); + tp = ctype(tp, tok = yyval->c); + switch (tok) { + case ENUM: case STRUCT: case UNION: + next(); + (tok == ENUM) ? enumdcl(tp) : structdcl(tp); + return true; + } break; - case ENUM: - tp = ctype(tp, ENUM); - next(); - enumdcl(tp); - return true; - case STRUCT: case UNION: - tp = ctype(tp, yytoken); - next(); - structdcl(tp); - return true; case IDEN: if (!tp->defined) { register struct symbol *sym; diff --git a/lex.c b/lex.c @@ -135,7 +135,7 @@ init_keywords(void) {"do", DO, DO}, {"double", TYPE, DOUBLE}, {"else", ELSE, ELSE}, - {"enum", ENUM, ENUM}, + {"enum", TYPE, ENUM}, {"extern", STORAGE, EXTERN}, {"float", TYPE, FLOAT}, {"for", FOR, FOR}, @@ -151,10 +151,10 @@ init_keywords(void) {"signed", TYPE, SIGNED}, {"sizeof", SIZEOF, SIZEOF}, {"static", STORAGE, STATIC}, - {"struct", STRUCT, STRUCT}, + {"struct", TYPE, STRUCT}, {"switch", SWITCH, SWITCH}, {"typedef", STORAGE, TYPEDEF}, - {"union", UNION, UNION}, + {"union", TYPE, UNION}, {"unsigned", TYPE, UNSIGNED}, {"void", TYPE, VOID}, {"volatile", TQUALIFIER, VOLATILE},