aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaël Gassmann <mael.gassmann@students.bfh.ch>2021-06-12 14:25:00 +0200
committerMaël Gassmann <mael.gassmann@students.bfh.ch>2021-06-12 14:25:00 +0200
commit817cfeba959d7938360ba8be478d0a452283347c (patch)
tree8112b4be5e0714d88036a2f44c83497f48e5c453
parent617fa5c11772911aa07a83b7206713cfbdcc4dc6 (diff)
[~] Now handling EOF char
-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);
}
}
}