Example #1
0
        public NFA closure()
        {
            NFA ret = new NFA(this);
            //add new start state
            int oldStartState = ret.startState;
            int newStartState = ret.addState(false);

            ret.startState = newStartState;
            ret.connect(newStartState, oldStartState, new EpsilonConnection(0, 0));
            //add connections from old end states to old start state
            ret.addConnectionToEndStates(oldStartState, new EpsilonConnection(0, 0));
            //old start state is a valid end state
            ret.endStates.Add(newStartState);
            ret.hasEpsilons = true;
            return(ret);
        }
Example #2
0
        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);
        }