public NFA conc(NFA second) { NFA ret = new NFA(this); //add new states ret.incrementIndices(second.numStates); foreach (Connection c in second.connections) { ret.connections.Add(c.copy()); } ret.calculateConnectionPerState(); //connect old end states to second's start state int secondStartState = second.startState; ret.addConnectionToEndStates(secondStartState, new EpsilonConnection(0, 0)); //fix end states as second's end states ret.endStates = new HashSet <int>(second.endStates); ret.hasEpsilons = true; return(ret); }
public NFA or(NFA second) { NFA ret = new NFA(this); //add states ret.incrementIndices(second.numStates); foreach (int i in second.endStates) { ret.endStates.Add(i); } //add connections between newly added states foreach (Connection c in second.connections) { ret.connections.Add(c.copy()); } //connect new start states with old start state ret.connect(ret.startState, second.startState, new EpsilonConnection(-1, -1)); ret.hasEpsilons = true; ret.calculateConnectionPerState(); return(ret); }