remove dfa

This commit is contained in:
ChUrl
2020-12-12 16:02:04 +01:00
parent 232b631744
commit f9dcebc82a
10 changed files with 0 additions and 591 deletions

View File

@ -1,16 +0,0 @@
package parser;
import java.util.Set;
public interface ILL1ParsingTable {
String get(String nonterminal, String terminal);
String getStartSymbol();
Set<String> getNonterminals();
Set<String> getTerminals();
String getEpsilon();
}

View File

@ -1,49 +0,0 @@
package util.dfa;
import java.util.Collection;
import java.util.Set;
public class DFA {
private final Set<INode> nodes;
private final INode start;
public DFA(Set<INode> nodes, INode start, Collection<IEdge> edges) {
this.nodes = nodes;
this.start = start;
for (INode node : nodes) {
edges.stream()
.filter(edge -> edge.getStart() == node)
.forEach(node::addEdge);
}
}
public INode getStart() {
return this.start;
}
public Set<INode> getNodes() {
return this.nodes;
}
public String accept(String word) {
return this.accept(word, this.start);
}
private String accept(String input, INode current) {
if (input.isEmpty()) {
return current.isFinal()
? current.getName() + " akzeptieren"
: current.getName() + " ablehnen";
}
char c = input.charAt(0);
if (!current.hasNext(c)) {
return current.getName() + " ablehnen";
}
return current.getName() + this.accept(input.substring(1), current.getNext(c));
}
}

View File

@ -1,8 +0,0 @@
package util.dfa;
public class DFANoSuchEdgeException extends RuntimeException {
public DFANoSuchEdgeException(String message) {
super(message);
}
}

View File

@ -1,29 +0,0 @@
package util.dfa;
public class Edge implements IEdge {
private final INode start;
private final INode end;
private final char read;
public Edge(INode start, char read, INode end) {
this.start = start;
this.read = read;
this.end = end;
}
@Override
public INode getStart() {
return this.start;
}
@Override
public INode getEnd() {
return this.end;
}
@Override
public char getChar() {
return this.read;
}
}

View File

@ -1,10 +0,0 @@
package util.dfa;
public interface IEdge {
INode getStart();
INode getEnd();
char getChar();
}

View File

@ -1,18 +0,0 @@
package util.dfa;
import java.util.Collection;
public interface INode {
String getName();
boolean isFinal();
void addEdge(IEdge edge);
Collection<IEdge> getEdges();
INode getNext(char c);
boolean hasNext(char c);
}

View File

@ -1,51 +0,0 @@
package util.dfa;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class Node implements INode {
private final String name;
private final boolean fin;
private final Map<Character, IEdge> edges = new HashMap<>();
public Node(String name, boolean fin) {
this.name = name;
this.fin = fin;
}
@Override
public String getName() {
return this.name;
}
@Override
public boolean isFinal() {
return this.fin;
}
@Override
public void addEdge(IEdge edge) {
this.edges.put(edge.getChar(), edge);
}
@Override
public Collection<IEdge> getEdges() {
return this.edges.values();
}
@Override
public INode getNext(char c) {
return Optional.ofNullable(this.edges.get(c))
.map(IEdge::getEnd)
.orElseThrow(() -> new DFANoSuchEdgeException("Can't read " + c + " when in " + this.name));
}
@Override
public boolean hasNext(char c) {
return Optional.ofNullable(this.edges.get(c))
.isPresent();
}
}

View File

@ -1,62 +0,0 @@
package util.tools;
import util.dfa.DFA;
import util.dfa.IEdge;
import util.dfa.INode;
import java.util.HashMap;
import java.util.Map;
public final class DFAViewUtil {
static int i;
private DFAViewUtil() {}
public static String toDot(DFA automaton) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
sb.append("digraph G {\n");
Map<INode, Integer> ids = new HashMap<>();
for (INode node : automaton.getNodes()) {
ids.put(node, i++);
}
for (INode node : automaton.getNodes()) {
sb.append("node");
sb.append(ids.get(node));
sb.append(" [label=\"");
sb.append(node.getName());
sb.append("\"");
if (node.isFinal()) {
sb.append(" shape=doublecircle");
}
sb.append("]\n");
if (automaton.getStart() == node) {
sb.append("start [style=invisible]\n");
sb.append("start -> node");
sb.append(ids.get(node));
sb.append("\n");
}
for (IEdge edge : node.getEdges()) {
sb.append("node");
sb.append(ids.get(node));
sb.append("->");
sb.append("node");
sb.append(ids.get(edge.getEnd()));
sb.append(" [label=\" ");
if (edge.getChar() == '\0') {
sb.append("&epsilon;");
} else {
sb.append(edge.getChar());
}
sb.append("\"]\n");
}
}
sb.append("}\n");
return sb.toString();
}
}