示例#1
0
文件: DFA.cs 项目: murcagr/compilers
        public bool Model(string word, List <char> alphabet)
        {
            if (word.Length == 0 && Finish.Contains(Initial))
            {
                return(true);
            }
            else if (word.Length == 0 && !Finish.Contains(Initial))
            {
                return(false);
            }
            else
            {
                CharEnumerator c = word.GetEnumerator();
                c.MoveNext();
                int letterI   = alphabet.IndexOf(c.Current);
                int nextState = DFATable[Initial][letterI][0];

                while (c.MoveNext())
                {
                    letterI   = alphabet.IndexOf(c.Current);
                    nextState = DFATable[nextState][letterI][0];
                }

                if (Finish.Contains(nextState))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#2
0
        public KeyValuePair <bool, int> Move(string inf, int offset)
        {
            Current = Start;
            bool IsItState = false;

            int Count = 0;
            int Index = offset;

            while (Index < inf.Length)
            {
                string s = inf[Index].ToString();
                if (transitions.ContainsKey(new KeyValuePair <int, string>(Current, s)))
                {
                    IsItState = true;
                    Count++;
                    Current = transitions[new KeyValuePair <int, string>(Current, s)];
                    Index++;
                }
                else
                {
                    break;
                }
            }
            if (!Finish.Contains(Current))
            {
                IsItState = false;
                Count     = 0;
            }

            return(new KeyValuePair <bool, int>(IsItState, Count));
        }