aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/cc/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/cc/lex.c')
-rw-r--r--sys/cmd/cc/lex.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c
index fc9dc0f..2a637da 100644
--- a/sys/cmd/cc/lex.c
+++ b/sys/cmd/cc/lex.c
@@ -38,9 +38,12 @@ getnsbyte(Lexer *lx)
b = getbyte(lx);
for (;;) {
if (b == EOF) {
- popio(lx);
- b = getbyte(lx);
- continue;
+ if (lx->io->link) {
+ popio(lx);
+ b = getbyte(lx);
+ continue;
+ } else
+ return b;
}
if (b >= RuneSelf || !isspace(b))
return b;
@@ -293,6 +296,12 @@ Dispatch:
lx->pos.line++;
goto Dispatch;
+ case '\\':
+ b = getbyte(lx);
+ if (b != '\n')
+ errorat(lx->pos, "'\\' without a trailing newline");
+ goto GetByte;
+
Tchar:
case '\'':
if (escapechar(lx, '\'', 0, 0, &v)) {
@@ -493,7 +502,10 @@ Dispatch:
}
lx->b = s;
/* reparse number, now with base info */
- while (b = getbyte(lx), (isdigit(b) || ('a' <= b && b <= 'f') || ('A' <= b && b <= 'F') || b == '_'))
+ while (b = getbyte(lx), (isdigit(b) ||
+ ('a' <= b && b <= 'f') ||
+ ('A' <= b && b <= 'F') ||
+ b == '_'))
*lx->b++ = b;
}
Rint:
@@ -545,10 +557,12 @@ Dispatch:
tok.kind |= Vun;
goto Return;
}
+
ungetbyte(lx);
- } else
- tok.kind |= Vint;
+ goto Return;
+ }
+ tok.kind |= Vint;
ungetbyte(lx);
goto Return;
@@ -624,7 +638,8 @@ Dispatch:
sym = lookup(&lx->sym, tok.val.s);
if (sym) {
io = makeio();
- io->buf.end += expandmacro(lx, sym, io->b);
+ io->buf.end += expandmacro(lx, sym, io->b);
+ *io->buf.end++ = EOF;
pushio(lx, io);
goto GetByte;
}
@@ -673,17 +688,14 @@ popio(Lexer *lx)
Io *prev;
prev = lx->io->link;
+ freeio(lx->io);
+
+ lx->io = prev;
if (!prev) {
- panicf("no buffer left");
+ return;
}
- /*
- * NOTE: should we copy over unget bytes here?
- * would modify the buffer...
- */
- freeio(lx->io);
lx->pos = prev->store;
- lx->io = prev;
}
// -----------------------------------------------------------------------
@@ -763,5 +775,18 @@ errorat(Pos x, byte *fmt, ...)
printf("\n");
va_end(args);
+ assert(0);
}
+void
+warnat(Pos x, byte *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ printf("warning:%s:%d:%d: ", osĀ·basename(x.path), x.line, x.col);
+ vprintf(fmt, args);
+ printf("\n");
+
+ va_end(args);
+}