From 817cfeba959d7938360ba8be478d0a452283347c Mon Sep 17 00:00:00 2001 From: Maƫl Gassmann Date: Sat, 12 Jun 2021 14:25:00 +0200 Subject: [~] Now handling EOF char --- calculator-java/src/main/java/ch/bfh/Main.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'calculator-java') diff --git a/calculator-java/src/main/java/ch/bfh/Main.java b/calculator-java/src/main/java/ch/bfh/Main.java index ea01185..2ded91a 100644 --- a/calculator-java/src/main/java/ch/bfh/Main.java +++ b/calculator-java/src/main/java/ch/bfh/Main.java @@ -3,6 +3,8 @@ package ch.bfh; import ch.bfh.lexer.LexerException; import ch.bfh.parser.ParserException; import ch.bfh.parser.StatementParser; + +import java.util.NoSuchElementException; import java.util.Scanner; public class Main { @@ -13,13 +15,16 @@ public class Main { while (true) { System.out.print("Type your expression: "); - String expression = scanner.nextLine(); try { + String expression = scanner.nextLine(); sp.parseStatement(expression); System.out.println("Result: " + sp.getValue()); } catch (LexerException | ParserException e) { System.out.println(e.getMessage()); + } catch (NoSuchElementException e){ + System.out.println("\nBuffer was closed. Exiting."); + System.exit(0); } } } -- cgit v1.2.3