aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/cc/lex.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-05-19 16:37:23 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-05-19 16:37:23 -0700
commit13772a8a2120017981d280bfe120fdbb74f27860 (patch)
tree0dcd2245580572297fe258f3bc4d681df2756680 /sys/cmd/cc/lex.c
parent02103dfd518faf327f7edc13695435308ddcead8 (diff)
fix: many bug fixes to number parsing
Diffstat (limited to 'sys/cmd/cc/lex.c')
-rw-r--r--sys/cmd/cc/lex.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c
index c84ea68..fc9dc0f 100644
--- a/sys/cmd/cc/lex.c
+++ b/sys/cmd/cc/lex.c
@@ -37,6 +37,11 @@ getnsbyte(Lexer *lx)
int b;
b = getbyte(lx);
for (;;) {
+ if (b == EOF) {
+ popio(lx);
+ b = getbyte(lx);
+ continue;
+ }
if (b >= RuneSelf || !isspace(b))
return b;
if (b == '\n')
@@ -477,24 +482,23 @@ Dispatch:
if (b == '.' || tolower(b) == 'e')
goto Tflt;
Tint:
- r = b;
n = 10;
s = lx->buf;
if (*s == '0') {
- b = *++s;
switch (b) {
case 'x': n = 16; break;
case 'b': n = 2; break;
case 'o': n = 8; break;
- default: --s;
- }
- if (s >= e) {
- errorat(lx->pos, "number overflows lexer buffer");
- goto Nospace;
+ default: goto Rint;
}
+ lx->b = s;
+ /* reparse number, now with base info */
+ while (b = getbyte(lx), (isdigit(b) || ('a' <= b && b <= 'f') || ('A' <= b && b <= 'F') || b == '_'))
+ *lx->b++ = b;
}
-
+ Rint:
v = 0;
+ r = b;
for (; s != lx->b ; s++) {
b = *s;
if (b == '_') continue;
@@ -593,7 +597,7 @@ Dispatch:
errorat(lx->pos, "identifier too long for buffer: %s", s);
goto Nospace;
}
- if (u >= RuneSelf) {
+ if (u != EOF && u >= RuneSelf) {
ungetbyte(lx);
r = getrune(lx);
if (!utf8·isletter(r) && !utf8·isdigit(r) && r != 0xb7) {
@@ -626,7 +630,6 @@ Dispatch:
}
goto Return;
-
default:
tok.kind = Anil;
errorat(lx->pos, "invalid token, crashing");