From 32fe5bdfd23f60cc46c7e7fe9e88cc558f76bfbf Mon Sep 17 00:00:00 2001 From: peshala-prabhapoorna Date: Wed, 23 Oct 2024 08:18:37 +0530 Subject: [PATCH 1/2] handle EOT signal gracefully --- note/answers/chapter08_statements.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/note/answers/chapter08_statements.md b/note/answers/chapter08_statements.md index 87fe3f840..99de63c53 100644 --- a/note/answers/chapter08_statements.md +++ b/note/answers/chapter08_statements.md @@ -84,7 +84,9 @@ hadError = false; System.out.print("> "); - Scanner scanner = new Scanner(reader.readLine()); + String line = reader.readLine(); + if (line == null) break; + Scanner scanner = new Scanner(line); List tokens = scanner.scanTokens(); Parser parser = new Parser(tokens); From e556437eab69e2ecc7c825f0f28b7b5b400b5356 Mon Sep 17 00:00:00 2001 From: peshala-prabhapoorna Date: Wed, 23 Oct 2024 08:33:59 +0530 Subject: [PATCH 2/2] print blank line at REPL exit for aesthetics --- note/answers/chapter08_statements.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/note/answers/chapter08_statements.md b/note/answers/chapter08_statements.md index 99de63c53..68a9be5a3 100644 --- a/note/answers/chapter08_statements.md +++ b/note/answers/chapter08_statements.md @@ -104,6 +104,8 @@ } } } + + System.out.println(); } ```