/** * Constructs a nfa containing two states which have transitions from first * to last * <p> * first -rs> last * @param scope * @param rs Range set containing the transition ranges. */ public NFA(Scope<NFAState<T>> scope, RangeSet rs) { this.scope = scope; first = new NFAState<>(scope); last = new NFAState<>(scope); first.addTransition(rs, last); } /**
/** * Construct a new nfa by cloning the other. * @param scope * @param other */ public NFA(Scope<NFAState<T>> scope, NFA<T> other) { this.scope = scope; Map<NFAState<T>,NFAState<T>> map = new NumMap<>(); for (NFAState<T> s : other) { NFAState<T> to = map.get(s); if (to == null) { to = new NFAState(scope, s, map); map.put(s, to); } } first = map.get(other.first); last = map.get(other.last); } /**
/** * Construct a new nfa state by cloning other state as well as all connected * states. * @param other * @param map */ NFAState(Scope<NFAState<T>> scope, NFAState<T> other, Map<NFAState<T>,NFAState<T>> map) { super(scope, other); map.put(other, this); for (Range r : other.transitions.keySet()) { Set<Transition<NFAState<T>>> s = other.transitions.get(r); for (Transition<NFAState<T>> t : s) { NFAState<T> to = map.get(t.getTo()); if (to == null) { to = new NFAState<>(scope, t.getTo(), map); } addTransition(r, to); } } } public boolean isAcceptImmediately()
/** * Changes this nfa to be a Kleenes star by adding epsilon moves from first to * last and vice versa. Extra epsilon connected state is added at the end. * This is to prevent future epsilon moves from flowing backwards. E.g (ab*)? */ public void star() { last.addEpsilon(first); first.addEpsilon(last); NFAState<T> s = new NFAState<>(scope); last.addEpsilon(s); last = s; } /**
last = new NFAState<>(scope); nfa1.last.addEpsilon(last); first.addEpsilon(nfa2.getFirst()); last = new NFAState<>(scope); nfa2.last.addEpsilon(last); first.addEpsilon(nfa1.getFirst()); first = new NFAState<>(scope); last = new NFAState<>(scope); first.addEpsilon(nfa1.getFirst()); first.addEpsilon(nfa2.getFirst());