aboutsummaryrefslogtreecommitdiff
path: root/src/Calculator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Calculator.java')
-rw-r--r--src/Calculator.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Calculator.java b/src/Calculator.java
new file mode 100644
index 0000000..c43ca9f
--- /dev/null
+++ b/src/Calculator.java
@@ -0,0 +1,30 @@
+import java.util.Scanner;
+
+public class Calculator {
+ public static void main(String[] args) {
+ // String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2
+ String expr = new String(" ");
+ Scanner sc = new Scanner(System.in);
+ Parser p;
+
+ if (args.length == 0) {
+ new GFrame("Calculator");
+ } else {
+ if (args[0].equals("-n")) {
+ System.out.println("Type \"exit\" or Ctrl+C to exit.");
+ while (true) {
+ System.out.print(">>> ");
+ expr = sc.nextLine();
+ if (!expr.equals("exit")) {
+ p = new Parser(expr);
+ System.out.println(p.eval());
+ } else {
+ sc.close();
+ break;
+ }
+ }
+ } else {
+ }
+ }
+ }
+}