scc

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

commit d56373f248e2f819620ae0e192bc09f79500398b
parent 3a0f8b791fc7bbd0f33a4004d22c5c36563b1b9b
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Wed, 17 Jun 2026 18:39:06 +0200

cc1: Fix handling of NOEXPAND and EXPAND

When they happen we have to modify disexpand and move
to the next character, but we were passing c with the
NOEXPAND or EXPAND value to the lexer, which due to a
casuality was finally working but only due to casuality
(a weird one).

Diffstat:
Msrc/cmd/scc-cc/cc1/lex.c | 33+++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/cmd/scc-cc/cc1/lex.c b/src/cmd/scc-cc/cc1/lex.c @@ -1076,27 +1076,28 @@ lex(void) { int c; - if ((c = skipspaces()) == EOF) +repeat: + switch (c = skipspaces()) { + case EOF: return EOFTOK; - - if (c == NOEXPAND) { - disexpand++; - input->begin = ++input->p; - } else if (c == EXPAND) { - disexpand--; - input->begin = ++input->p; - } - - if (isalpha(c) || c == '_') + case NOEXPAND: + case EXPAND: + disexpand += (c == NOEXPAND) ? +1 : -1; + input->p++; + goto repeat; + case '_': return iden(); - else if (isdigit(c)) - return number(); - else if (c == '"') + case '"': return string(); - else if (c == '\'') + case '\'': return character(); - else + default: + if (isalpha(c)) + return iden(); + if (isdigit(c)) + return number(); return operator(); + } } int