From d48380bd87dcef4b095b2a4e578d4461e68df73c Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Mon, 17 Jul 2017 15:22:19 +0200 Subject: Working on a way to CTL over DAG in Kodkod. --- cfg-to-paths/src/QuickParser.java | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 cfg-to-paths/src/QuickParser.java (limited to 'cfg-to-paths/src/QuickParser.java') diff --git a/cfg-to-paths/src/QuickParser.java b/cfg-to-paths/src/QuickParser.java new file mode 100644 index 0000000..47cea27 --- /dev/null +++ b/cfg-to-paths/src/QuickParser.java @@ -0,0 +1,58 @@ +/* FIXME: Finer imports */ +import java.io.*; +import java.util.regex.*; +import java.util.*; + +public class QuickParser +{ + private static final Pattern instr_pattern; + private final BufferedReader buffered_reader; + + static + { + instr_pattern = Pattern.compile("\\((?[a-z_0-9 \"]+)\\)"); + } + public QuickParser (final String filename) + throws FileNotFoundException + { + buffered_reader = new BufferedReader(new FileReader(filename)); + } + + public void finalize () + throws IOException + { + buffered_reader.close(); + } + + public String[] parse_line () + throws IOException + { + final List result; + final Matcher matcher; + String line; + + do + { + line = buffered_reader.readLine(); + + if (line == null) + { + return new String[0]; + } + + line = line.replaceAll("\\s+"," "); + } + while (line.length() < 3 || line.startsWith(";")); + + matcher = instr_pattern.matcher(line); + + if (!matcher.find()) + { + System.err.println("[E] Invalid instruction \"" + line + "\""); + + return null; + } + + return matcher.group(1).split(" |\t"); + } +} -- cgit v1.2.3-70-g09d2