ref: 941a776c59a79b6d64d07d09b38f3e9b00feeee3
parent: f83f8e2064258e2d96e94b4702943ddf1b30239e
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jul 29 07:11:18 EDT 2012
New function operator in lexical analysis This new function allow a simpler and cleaner next function
--- a/lex.c
+++ b/lex.c
@@ -124,6 +124,25 @@
}
}
+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 @@
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();
}
}