Beispiel #1
0
        public Nfa BuildConcat(INfa concat1, INfa concat2)
        {
            var shiftedConcat2 = new ShiftedNfa(concat2, concat1.Size - 1);
            var nfa            = new Nfa(concat1.Size + concat2.Size - 1);

            nfa.FillStates(concat1);
            nfa.FillStates(shiftedConcat2);

            return(nfa);
        }
Beispiel #2
0
        public Nfa BuildStar(INfa inner)
        {
            var shiftedInner = new ShiftedNfa(inner, 1);
            var nfa          = new Nfa(shiftedInner.Size + 2);

            nfa.FillStates(shiftedInner);

            nfa.AddEpsilonTransition(nfa.Initial, shiftedInner.Initial);
            nfa.AddEpsilonTransition(nfa.Initial, nfa.Final);
            nfa.AddEpsilonTransition(shiftedInner.Final, nfa.Final);
            nfa.AddEpsilonTransition(shiftedInner.Final, shiftedInner.Initial);

            return(nfa);
        }
Beispiel #3
0
        public Nfa BuildAlter(INfa alter1, INfa alter2)
        {
            var shiftedAlter1 = new ShiftedNfa(alter1, 1);
            var shiftedAlter2 = new ShiftedNfa(alter2, alter1.Size + 1);
            var newNfa        = new Nfa(alter1.Size + alter2.Size + 2);

            newNfa.FillStates(shiftedAlter1);
            newNfa.FillStates(shiftedAlter2);

            newNfa.AddEpsilonTransition(0, shiftedAlter1.Initial);
            newNfa.AddEpsilonTransition(0, shiftedAlter2.Initial);

            newNfa.AddEpsilonTransition(shiftedAlter1.Final, newNfa.Final);
            newNfa.AddEpsilonTransition(shiftedAlter2.Final, newNfa.Final);

            return(newNfa);
        }