scc

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

commit b4a75db28d8358ead5216591676f1c2e5867ebb4
parent 0214edbad28232ca828f44aa43dd413fe18edaa9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Apr 2014 22:25:01 +0200

Fix next()

+ and - are operators, and they must be operators since they
can be part of +=, -=, ++, -- tokens, so they are no a valid
part of a number.

Diffstat:
Mlex.c | 11+++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/lex.c b/lex.c @@ -59,14 +59,9 @@ type: static uint8_t number(void) { - register char ch, *bp = yybuf; + register char ch, *bp; static char base; - if ((ch = getc(yyin)) == '+' || ch == '-') - *bp++ = ch; - else - ungetc(ch, yyin); - if ((ch = getc(yyin)) == '0') { if (toupper(ch = getc(yyin)) == 'X') { base = 16; @@ -79,7 +74,7 @@ number(void) ungetc(ch, yyin); } - for ( ; bp < &yybuf[IDENTSIZ]; *bp++ = ch) { + for (bp = yybuf ; bp < &yybuf[IDENTSIZ]; *bp++ = ch) { ch = getc(yyin); switch (base) { case 8: @@ -405,7 +400,7 @@ next(void) ungetc(c, yyin); if (isalpha(c) || c == '_') yyntoken = iden(); - else if (isdigit(c) || c == '-' || c == '+') + else if (isdigit(c)) yyntoken = number(); else if (c == '"') yyntoken = string();