aboutsummaryrefslogtreecommitdiffstats
path: root/main/exception
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2016-06-13 23:16:54 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2016-07-26 19:46:50 +0300
commit12eeefcdba1ee392f033f51e6b9826eaae3c4de6 (patch)
tree061f3472bfc924dfa05b46f3aeab76b788b86914 /main/exception
parent560e490ea44970edca22181cc2726f0b2ebb82c9 (diff)
Add tokenizer, parser and support for certain operations
Diffstat (limited to 'main/exception')
-rw-r--r--main/exception/ExceptionManager.java29
-rw-r--r--main/exception/InterpreterException.java33
2 files changed, 62 insertions, 0 deletions
diff --git a/main/exception/ExceptionManager.java b/main/exception/ExceptionManager.java
new file mode 100644
index 0000000..0ceb25b
--- /dev/null
+++ b/main/exception/ExceptionManager.java
@@ -0,0 +1,29 @@
+package com.jantuomi.interpreter.main.exception;
+
+import java.util.List;
+
+/**
+ * Created by jan on 10.6.2016.
+ */
+public class ExceptionManager {
+
+ private static final ExceptionManager instance = new ExceptionManager();
+
+ private ExceptionManager() {
+ }
+
+ public static ExceptionManager getInstance() {
+ return instance;
+ }
+
+ public static void raise(InterpreterException.Exception ex, int line, List<String> args) {
+ InterpreterException e = new InterpreterException(ex);
+ String output = e.what();
+ for (String arg : args) {
+ output = String.format(output, arg);
+ }
+ System.err.println(String.format("[%s] line: %d %s", ex.toString(), line, output));
+ }
+
+
+}
diff --git a/main/exception/InterpreterException.java b/main/exception/InterpreterException.java
new file mode 100644
index 0000000..8129012
--- /dev/null
+++ b/main/exception/InterpreterException.java
@@ -0,0 +1,33 @@
+package com.jantuomi.interpreter.main.exception;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by jan on 12.6.2016.
+ */
+public class InterpreterException {
+
+ public enum Exception {
+ IllegalTokenException,
+ UnknownOperatorException
+ }
+
+ public static Map<Exception, String> errorTexts = new HashMap<>();
+
+ static {
+ errorTexts.put(Exception.IllegalTokenException, "Illegal token %s found.");
+ errorTexts.put(Exception.UnknownOperatorException, "Unknown operator %s found.");
+ }
+
+ private Exception exception;
+
+ public InterpreterException(Exception e) {
+ exception = e;
+ }
+
+ public String what() {
+ return errorTexts.get(exception);
+ }
+}