-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
27 lines (24 loc) · 876 Bytes
/
Copy pathMain.java
File metadata and controls
27 lines (24 loc) · 876 Bytes
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
import Parser.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<String, Double> variables = new HashMap<>();
while (true) {
System.out.print("Enter expression: ");
String input = scanner.nextLine();
if (input.equalsIgnoreCase("exit")) break;
try {
Tokenizer tokenizer = new Tokenizer(input);
Parser parser = new Parser(tokenizer);
Node ast = parser.parseExpression(0);
double result = ast.evaluate(variables);
System.out.println("Result: " + result);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
}