summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'instr-to-kodkod/cfg-to-paths/src/ControlFlow.java')
-rw-r--r--instr-to-kodkod/cfg-to-paths/src/ControlFlow.java142
1 files changed, 142 insertions, 0 deletions
diff --git a/instr-to-kodkod/cfg-to-paths/src/ControlFlow.java b/instr-to-kodkod/cfg-to-paths/src/ControlFlow.java
new file mode 100644
index 0000000..93d20ba
--- /dev/null
+++ b/instr-to-kodkod/cfg-to-paths/src/ControlFlow.java
@@ -0,0 +1,142 @@
+import java.io.*;
+
+public class ControlFlow
+{
+ public static boolean load_file
+ (
+ final String filename
+ )
+ throws FileNotFoundException
+ {
+ final QuickParser qp;
+ String[] input;
+ boolean success;
+
+ qp = new QuickParser(filename);
+
+ for (;;)
+ {
+ try
+ {
+ input = qp.parse_line();
+
+ if (input == null)
+ {
+ qp.finalize();
+
+ return false;
+ }
+ else if (input.length == 0)
+ {
+ qp.finalize();
+
+ break;
+ }
+ }
+ catch (final IOException e)
+ {
+ System.err.println
+ (
+ "[E] IO error while parsing file \""
+ + filename
+ + "\":"
+ /* FIXME: can be null */
+ + e.getMessage()
+ );
+
+ return false;
+ }
+
+ if (input[0].equals("add_element"))
+ {
+ success = handle_add_element(input);
+ }
+ else if (input[0].equals("node_connect"))
+ {
+ success = handle_add_connect_to(input);
+ }
+ else if (input[0].equals("is_terminal"))
+ {
+ success = handle_is_terminal(input);
+ }
+ else
+ {
+ continue;
+ }
+
+ if (!success)
+ {
+ System.err.println
+ (
+ "[E] An erroneous instruction was found in file \""
+ + filename
+ + "\"."
+ );
+
+ try
+ {
+ qp.finalize();
+ }
+ catch (final Exception e)
+ {
+ System.err.println("[E] Additionally:");
+ e.printStackTrace();
+ }
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private static boolean handle_add_element
+ (
+ final String[] input
+ )
+ {
+ if (input.length != 3)
+ {
+ return false;
+ }
+
+ if (!input[1].equals("node"))
+ {
+ return true;
+ }
+
+ Node.handle_add_node(input[2]);
+
+ return true;
+ }
+
+ private static boolean handle_is_terminal
+ (
+ final String[] input
+ )
+ {
+ if (input.length != 2)
+ {
+ return false;
+ }
+
+ Node.handle_is_terminal(input[1]);
+
+ return true;
+ }
+
+ private static boolean handle_add_connect_to
+ (
+ final String[] input
+ )
+ {
+ if ((input.length != 3))
+ {
+ return false;
+ }
+
+ return Node.handle_connect_to(input[1], input[2]);
+ }
+
+ private ControlFlow () {} /* Utility Class */
+}