ref: 8582d9985a73836ca6e53a5f7c50b71ec7466168
parent: eab03ebe04b15733d202211eee7b995f8dd6b39c
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 21 17:56:28 EDT 2012
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.
--- a/lex.c
+++ b/lex.c
@@ -160,15 +160,14 @@
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();
}
}