scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 8582d9985a73836ca6e53a5f7c50b71ec7466168
parent eab03ebe04b15733d202211eee7b995f8dd6b39c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Aug 2012 21:56:28 +0200

Make simplest next()

Once we know we have to look ahead next character, is common to all cases
ungetc the character already read, so instead of having an ungetc in all the
cases, the best solution is doing an unique ungetc.

Diffstat:
lex.c | 15+++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/lex.c b/lex.c @@ -160,15 +160,14 @@ next(void) aheadtok = NOTOK; } else if (!skip()) { yytoken = EOFTOK; - } else if (isalpha(c = getc(yyin)) || c == '_') { - ungetc(c, yyin); - yytoken = iden(); - } else if (isdigit(c)) { - ungetc(c, yyin); - yytoken = number(); } else { - ungetc(c, yyin); - yytoken = operator(); + ungetc(c = getc(yyin), yyin); + if (isalpha(c) || c == '_') + yytoken = iden(); + else if (isdigit(c)) + yytoken = number(); + else + yytoken = operator(); } }