Skip to content
Snippets Groups Projects
Commit fbd6483a authored by Thomas's avatar Thomas
Browse files

timbuk parser

parent 61a0e9c0
No related branches found
No related tags found
No related merge requests found
import com.google.common.collect.Lists;
import net.automatalib.automata.fsa.impl.compact.CompactNFA;
import net.automatalib.util.automata.builders.FSABuilder;
import net.automatalib.visualization.Visualization;
import net.automatalib.words.Alphabet;
import net.automatalib.words.impl.Alphabets;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.*;
// Sorry, not a general parser, just for these files
......@@ -12,11 +16,13 @@ public class TimbukParser {
public Set<GraphvizParser.Edge> edges;
public Set<String> initial;
public Set<String> accepting;
public Set<String> inputs;
public TimbukParser(Path filename) throws IOException {
edges = new HashSet<>();
initial = new HashSet<>();
accepting = new HashSet<>();
inputs = new HashSet<>();
Scanner s = new Scanner(filename);
while(s.hasNextLine()) {
......@@ -36,6 +42,7 @@ public class TimbukParser {
int sep = parts[0].indexOf("(");
String label = parts[0].substring(0, sep).trim();
inputs.add(label);
String from = parts[0].substring(sep+1, parts[0].length()-1);
edges.add(new GraphvizParser.Edge(from, parts[1].trim(), label));
......@@ -43,4 +50,20 @@ public class TimbukParser {
}
}
}
CompactNFA<String> createNFA() {
List<String> inputList = Lists.newArrayList(inputs.iterator());
Alphabet<String> alphabet = Alphabets.fromList(inputList);
FSABuilder<?, String, CompactNFA<String>> builder = new FSABuilder<>(new CompactNFA<>(alphabet));
initial.forEach(builder::withInitial);
accepting.forEach(builder::withAccepting);
for (GraphvizParser.Edge e : edges) {
builder.from(e.from).on(e.label).to(e.to);
}
return builder.create();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment