aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/compiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'clox/src/compiler.c')
-rw-r--r--clox/src/compiler.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/clox/src/compiler.c b/clox/src/compiler.c
index 71961ef..2cc2ee4 100644
--- a/clox/src/compiler.c
+++ b/clox/src/compiler.c
@@ -4,4 +4,20 @@
#include "compiler.h"
#include "scanner.h"
-void compile(const char *source) { initScanner(source); }
+void compile(const char *source) {
+ initScanner(source);
+ int line = -1;
+ for (;;) {
+ Token token = scanToken();
+ if (token.line != line) {
+ printf("%4d ", token.line);
+ line = token.line;
+ } else {
+ printf(" | ");
+ }
+ printf("%2d '%.*s'\n", token.type, token.length, token.start);
+
+ if (token.type == TOKEN_EOF)
+ break;
+ }
+}