Ejemplo n.º 1
0
        // returns start and end index (both inclusive) of mid word
        private static TwoTuple <int, int> detectLoopFromState(StringDFA dfa, string currentState, string word, int n)
        {
            List <string> statesVisited = new List <string>();

            if (!dfa.Accepts(word))
            {
                throw new PumpingLemmaException("Automaton does not accept this word!");
            }

            statesVisited.Add(currentState);
            int currentLetter = 0;

            while (currentLetter <= n && currentLetter < word.Length)
            {
                string newState = dfa.delta[new TwoTuple <string, string>(currentState, word.ElementAt(currentLetter) + "")];
                if (statesVisited.Contains(newState))
                {
                    int index = statesVisited.IndexOf(newState);
                    return(new TwoTuple <int, int>(index, currentLetter));
                }
                else
                {
                    currentLetter++;
                    currentState = newState;
                    statesVisited.Add(currentState);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public static int RegularGetI(StringDFA dfa, string start, string mid, string end)
        {
            if (!dfa.Accepts(start + end))
            {
                return(0);
            }
            if (RegularCheckSplit(dfa, start, mid, end))
            {
                return(1); //AI admits defeat
            }
            int i = 2;

            while (dfa.Accepts(pumpMid(start, mid, end, i)))
            {
                i++;
                //for debuugging purposes:
                if (i > 99)
                {
                    return(1);
                }
            }
            return(i);
        }
Ejemplo n.º 3
0
        /*
         * ----------------------------------------------------------------------------------------------------
         *                                       Decision Making
         * ----------------------------------------------------------------------------------------------------
         */

        public static string RegularCheckWord(StringDFA dfa, int n, string word)
        {
            if (word.Length < n)
            {
                return("<false>Word is too short.</false>");
            }

            foreach (char c in word)
            {
                if (!dfa.alphabet.Contains(c + ""))
                {
                    return("<false>Word contains illegal letters.</false>");
                }
            }

            if (dfa.Accepts(word))
            {
                return("<true></true>");
            }

            return("<false>Word is not in the language.</false>");
        }
Ejemplo n.º 4
0
 public static bool RegularCheckI(StringDFA dfa, string start, string mid, string end, int i)
 {
     return(dfa.Accepts(pumpMid(start, mid, end, i)));
 }