/** * Constructs a dfa from using first nfa state as starting state. * @param scope * @return */ public DFA<T> constructDFA(Scope<DFAState<T>> scope) { return new DFA<>(first.constructDFA(scope), scope.count()); } /**
/** * Concatenates this to nfa by making epsilon move from this last to nfa first. * @param nfa */ public void concat(NFA<T> nfa) { last.addEpsilon(nfa.getFirst()); last = nfa.last; } /**
public void dump(PrintStream p) { for (DFAState<T> s : this) { for (Transition<DFAState<T>> t : s.getTransitions()) { p.println(stateDump(s)+"-"+t.getCondition()+">"+stateDump(t.getTo())); } } }
public void distribute() { distribute(dfa.getRoot(), dfa.initialSize()); } private void distribute(DFAState<T> state, int rootCount)
/** * Creates an empty nfa * @param scope */ public NFA(Scope<NFAState<T>> scope) { this.scope = scope; first = new NFAState<>(scope); last = new NFAState<>(scope); first.addEpsilon(last); } /**
private NFA<T> concat(NFA<T> nfa2, NFA<T> nfa1) { nfa1.concat(nfa2); return nfa1; }
private NFA<T> quess(NFA<T> nfa) { nfa.opt(); return nfa; }
/** * Changes this nfa to be optional by adding epsilon from first to last. */ public void opt() { first.addEpsilon(last); }
private NFA<T> star(NFA<T> nfa) { nfa.star(); return nfa; }
@Override public Iterator<NFAState<T>> iterator() { return new DiGraphIterator<>(first); }
/** * Copy constructor * @param other */ protected State(Scope scope, State<T> other) { this.scope = scope; this.number = scope.next(); token = other.token; }
@Override protected void branch(DFAState<T> x) { addCandidate(x); }
public FindCompiler(DFA<T> dfa, T errorToken, T eofToken) { super(dfa, errorToken, eofToken); dfa.calculateMaxFindSkip(); }
/** * Returns true if this dfa can accept empty string. * @return */ public boolean acceptEmpty() { return root.isAccepting(); } /**
@Override public Iterator<DFAState<T>> iterator() { return new DiGraphIterator<>(this); }
public State(Scope scope) { this.scope = scope; this.number = scope.next(); }
@Override public Iterator<NFAState<T>> iterator() { return new DiGraphIterator<>(this); }
@Override public Iterator<DFAState<T>> iterator() { return new DiGraphIterator<>(root); }