From baa37871d9b71d3f94cc8acca8d375ee1232d7f0 Mon Sep 17 00:00:00 2001 From: Ibrahim Muftee Date: Tue, 14 Jul 2026 22:18:38 -0500 Subject: chapter 01 --- repl/repl.odin | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 repl/repl.odin (limited to 'repl') diff --git a/repl/repl.odin b/repl/repl.odin new file mode 100644 index 0000000..bb4a1b2 --- /dev/null +++ b/repl/repl.odin @@ -0,0 +1,30 @@ +package repl + +import "../lexer" +import "../token" +import "core:bufio" +import "core:fmt" +import "core:io" + +PROMPT :: ">> " + +start :: proc(r: io.Reader, w: io.Writer) { + s := bufio.scanner_init(&bufio.Scanner{}, r) + defer bufio.scanner_destroy(s) + + for { + fmt.wprintf(w, PROMPT) + scanned := bufio.scan(s) + if !scanned { + return + } + + line := bufio.scanner_text(s) + l := lexer.new(line) + + eof: token.EOF + for tok := lexer.next_token(&l); tok != eof; tok = lexer.next_token(&l) { + fmt.wprintf(w, "%v\n", tok) + } + } +} -- cgit v1.2.3