aboutsummaryrefslogtreecommitdiff
path: root/calculator-java/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'calculator-java/src/main')
-rw-r--r--calculator-java/src/main/java/ch/bfh/Main.java7
1 files changed, 6 insertions, 1 deletions
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);
}
}
}