diff options
author | Maël Gassmann <mael.gassmann@students.bfh.ch> | 2021-06-11 11:17:45 +0200 |
---|---|---|
committer | Maël Gassmann <mael.gassmann@students.bfh.ch> | 2021-06-11 11:17:45 +0200 |
commit | 403c6a951e890d3e1914779ee35576859a38d33e (patch) | |
tree | ff2d5182ad4e72b335624c61a7d48364de61807c /calculator-java/src/main/java/ch/bfh/Main.java | |
parent | 126a6c85b60ad07fa29ab48315f0f195fb45d854 (diff) |
[+] implemented the 'shell' UI, [~] Small corrections had to be made in the parser
Diffstat (limited to 'calculator-java/src/main/java/ch/bfh/Main.java')
-rw-r--r-- | calculator-java/src/main/java/ch/bfh/Main.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/calculator-java/src/main/java/ch/bfh/Main.java b/calculator-java/src/main/java/ch/bfh/Main.java index b0dedf3..302f5ed 100644 --- a/calculator-java/src/main/java/ch/bfh/Main.java +++ b/calculator-java/src/main/java/ch/bfh/Main.java @@ -3,21 +3,25 @@ package ch.bfh; import ch.bfh.parser.ExpressionParser; import java.util.Arrays; +import java.util.Scanner; public class Main { public static void main(String[] args){ - CalculatorLexer cl = new CalculatorLexer(); - - //TODO - command line reader instead of arg - - // Combines the arguments & init the lexer - cl.initLexer( - Arrays.stream(args).reduce("", (expression, arg) -> expression + arg) - ); - - ExpressionParser ep = new ExpressionParser(cl); - - System.out.println(ep.getValue()); + Scanner scanner = new Scanner(System.in); + + while (true) { + CalculatorLexer cl = new CalculatorLexer(); + System.out.print("Type your expression: "); + String expression = scanner.nextLine(); + + try { + cl.initLexer(expression); + ExpressionParser ep = new ExpressionParser(cl); + System.out.println(ep.getValue()); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } } } |