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.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/sys/cmd/cc/lex.c b/sys/cmd/cc/lex.c
index 6b85d8c..6d3da59 100644
--- a/sys/cmd/cc/lex.c
+++ b/sys/cmd/cc/lex.c
@@ -1,8 +1,28 @@
#include "cc.h"
-
#include <libn/macro/map.h>
// -----------------------------------------------------------------------
+// printing functions
+
+void
+puttok(Token tok)
+{
+ if (tok.kind < Alit)
+ printf("%s", tokens[tok.kind]);
+ else if (tok.kind & Alit) {
+ if (tok.kind & Vchar)
+ if (tok.kind & Vint)
+ if (tok.kind & Vlong)
+ if (tok.kind & Vvlong)
+ printf("literal <%lld>", tok.val.i);
+ if (tok.kind & Vfloat)
+ printf("literal <%f>", tok.val.f);
+ printf("literal <%s>", tok.val.s);
+ } else
+ printf("ident <%s>", tok.val.s);
+}
+
+// -----------------------------------------------------------------------
// simple wrappers
byte
@@ -607,7 +627,7 @@ static
int
moresymtab(SymTab *tab, int n)
{
- MAP_GROW(tab, string, Sym*, n, PTR_HASH, mem·sys.alloc, mem·sys.free, nil);
+ MAP_GROW(tab, string, Sym*, n, PTR_HASH, ·calloc, ·free, nil);
}
static
@@ -642,8 +662,9 @@ errorat(Pos x, byte *fmt, ...)
va_start(args, fmt);
printf("error %d: ", x.line);
-
vprintf(fmt, args);
+ printf("\n");
+
va_end(args);
}