scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 323563334c17544e1c9134dc8cd8e3cbdb33c1c9
parent 4245cbfab4b58fc0c0ab667fb2bc66c411963d0c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 11 Apr 2014 16:02:57 +0200

Fix lexical analysis of logical operators

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

diff --git a/lex.c b/lex.c @@ -227,6 +227,23 @@ relational(uint8_t op, uint8_t equal, uint8_t shift, uint8_t assig) } static uint8_t +logic(uint8_t op, uint8_t equal, uint8_t logic) +{ + register int c = getc(yyin); + + yybuf[1] = c; + yybuf[2] = '\0'; + + if (c == '=') + return equal; + if (c == op) + return logic; + ungetc(c, yyin); + yybuf[1] = '\0'; + return op; +} + +static uint8_t operator(void) { register uint8_t c = getc(yyin); @@ -236,13 +253,13 @@ operator(void) switch (c) { case '<': return relational('<', LE, SHL, SHL_EQ); case '>': return relational('>', GE, SHR, SHR_EQ); + case '&': return logic('&', AND_EQ, AND); + case '|': return logic('|', OR_EQ, OR); case '=': return follow('=', EQ, '='); case '^': return follow('=', XOR_EQ, '^'); case '*': return follow('=', MUL_EQ, '*'); case '/': return follow('=', DIV_EQ, '/'); case '!': return follow('=', NE, '!'); - case '&': return follow('=', AND_EQ, AND); - case '|': return follow('=', OR_EQ, OR); case '-': return minus(); case '+': return plus(); default: return c;