From 4143259eb3df16470dc2d93371e65e53d027243b Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 2 Aug 2021 18:35:10 -0700 Subject: Chapter 16.2 --- clox/src/compiler.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'clox/src/compiler.c') 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; + } +} -- cgit v1.2.3-54-g00ecf