scc

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

commit 941a776c59a79b6d64d07d09b38f3e9b00feeee3
parent f83f8e2064258e2d96e94b4702943ddf1b30239e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 29 Jul 2012 11:11:18 +0200

New function operator in lexical analysis

This new function allow a simpler and cleaner next function

Diffstat:
Mlex.c | 34+++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/lex.c b/lex.c @@ -124,6 +124,25 @@ static unsigned char minus(void) } } +static unsigned char operator(void) +{ + register unsigned char c; + + switch (c = getc(yyin)) { + case '=': return follow('=', EQ, 0); + case '^': return follow('^', XOR_EQ, 0); + case '*': return follow('*', MUL_EQ, 0); + case '!': return follow('!', NE, 0); + case '+': return follow('+', ADD_EQ, INC); + case '&': return follow('&', AND_EQ, AND); + case '|': return follow('|', OR_EQ, OR); + case '<': return rel_shift('<'); + case '>': return rel_shift('>'); + case '-': return minus(); + default: return c; + } +} + void next(void) { register unsigned char c; @@ -140,19 +159,8 @@ void next(void) ungetc(c, yyin); yytoken = number(); } else { - switch (c) { - case '=': yytoken = follow('=', EQ, 0); break; - case '^': yytoken = follow('^', XOR_EQ, 0); break; - case '*': yytoken = follow('*', MUL_EQ, 0); break; - case '!': yytoken = follow('!', NE, 0); break; - case '+': yytoken = follow('+', ADD_EQ, INC); break; - case '&': yytoken = follow('&', AND_EQ, AND); break; - case '|': yytoken = follow('|', OR_EQ, OR); break; - case '<': yytoken = rel_shift('<'); break; - case '>': yytoken = rel_shift('>'); break; - case '-': yytoken = minus(); break; - default: yytoken = c; - } + ungetc(c, yyin); + yytoken = operator(); } }