aboutsummaryrefslogtreecommitdiff
path: root/calculator-java/src/main/java/ch/bfh/Main.java
blob: 2ded91a61790637089d376c00f0fb4aa5a673ce4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        StatementParser sp = new StatementParser();

        while (true) {
            System.out.print("Type your expression: ");

            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);
            }
        }
    }
}