diff options
author | Tom Willemse | 2021-08-02 18:35:10 -0700 |
---|---|---|
committer | Tom Willemse | 2021-08-02 18:35:10 -0700 |
commit | 4143259eb3df16470dc2d93371e65e53d027243b (patch) | |
tree | c64733b53a6e6344eb1443a080af5aa5ba960a6a /clox/src/compiler.c | |
parent | b131e343bb8a2b126a5370138d826d87d74fce30 (diff) | |
download | crafting-interpreters-4143259eb3df16470dc2d93371e65e53d027243b.tar.gz crafting-interpreters-4143259eb3df16470dc2d93371e65e53d027243b.zip |
Chapter 16.2
Diffstat (limited to 'clox/src/compiler.c')
-rw-r--r-- | clox/src/compiler.c | 18 |
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; + } +} |