| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-03 15:28:17 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-03 15:28:17 +0200 | 
| commit | 90bb7e959496c3a12bebe055f6344b9f06f22809 (patch) | |
| tree | 6635decc697d91c8cba6da9db8959b706ad9842f /instr-to-kodkod/cfg-to-paths/src/ControlFlow.java | |
| parent | c5a23ef9d6ab1e89b85016831fc8b2431f68f87f (diff) | |
Improving clarity through better Makefiles.
Diffstat (limited to 'instr-to-kodkod/cfg-to-paths/src/ControlFlow.java')
| -rw-r--r-- | instr-to-kodkod/cfg-to-paths/src/ControlFlow.java | 142 | 
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 */ +} | 


