From 02103dfd518faf327f7edc13695435308ddcead8 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 19 May 2020 14:02:28 -0700 Subject: feat: added prototype of stringizer & tokenizer macro operators --- sys/cmd/cc/lex.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'sys/cmd/cc/lex.c') diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c index c1ee6a4..c84ea68 100644 --- a/sys/cmd/cc/lex.c +++ b/sys/cmd/cc/lex.c @@ -180,6 +180,7 @@ oct: continue; } ungetbyte(lx); + break; } if (l > 255) errorat(lx->pos, "octal escape value > 255: %d", l); @@ -253,7 +254,8 @@ Dispatch: if (b >= RuneSelf || b == '_') goto Talpha; if (isalpha(b)) { - goto Talpha; + if (b != 'L') + goto Talpha; n = b; b = getbyte(lx); @@ -267,8 +269,12 @@ Dispatch: tok.val.r = v; goto Return; } + if (b == '"') + goto TLstr; ungetbyte(lx); b = n; + + goto Talpha; } if (isdigit(b)) goto Tnum; @@ -321,7 +327,22 @@ Dispatch: intern(&tok.val.s); str·free(s); - break; + goto Return; + + TLstr: + s = str·makecap("", 0, 8); + // NOTE: this violates strict aliasing + for (;;) { + if (escapechar(lx, '"', 1, 0, &v)) + break; + str·appendlen(&s, sizeof(wchar_t), (byte*)&v); + } + tok.kind = Alit | Vwstr; + tok.val.s = s; + intern(&tok.val.s); + + str·free(s); + goto Return; case '.': tok.kind = Adot; -- cgit v1.2.1