Пример #1
0
        protected string[] SplitWord(string word)
        {
            var result = new List <string>();

            for (int i = 0; i < word.Length; ++i)
            {
                int    j             = 1;
                string substringWord = string.Empty;

                while (i + j < word.Length + 1)
                {
                    substringWord = word.Substring(i, j);

                    if (!Alphabet.Contains(substringWord))
                    {
                        ++j;
                    }
                    else
                    {
                        result.Add(substringWord);
                        substringWord = string.Empty;
                        i            += j - 1;
                        break;
                    }
                }

                if (substringWord.Length != 0)
                {
                    result.Add(substringWord);
                    i += substringWord.Length - 1;
                }
            }

            return(result.ToArray());
        }
Пример #2
0
        protected bool CheckWord(IEnumerable <string> word)
        {
            foreach (var symbol in word)
            {
                if (!Alphabet.Contains(symbol))
                {
                    Console.WriteLine("Word <" + string.Concat(word) + "> contains an illegal symbol: <" + symbol + ">");
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        public bool accept(U[] input)
        {
            if (!isValid())
            {
                throw new AutomatonInvalidException();
            }
            var currState = StartState;

            foreach (U u in input)
            {
                if (!Alphabet.Contains(u))
                {
                    throw new System.ArgumentException($"{u} is not part of alphabet");
                }
                currState = Transitions[currState][u];
            }

            return(EndStates.Contains(currState));
        }
Пример #4
0
        public bool accept(U[] input)
        {
            if (!isValid())
            {
                throw new AutomatonInvalidException();
            }

            var currStates = StartStates;

            foreach (U u in input)
            {
                if (!Alphabet.Contains(u))
                {
                    throw new System.ArgumentException($"{u} is not part of alphabet");
                }
                HashSet <T> newStates = new HashSet <T>();
                foreach (T state in currStates)
                {
                    if (!Transitions.ContainsKey(state))
                    {
                        continue;
                    }
                    if (Transitions[state].ContainsKey(Epsilon))
                    {
                        newStates.UnionWith(Transitions[state][Epsilon]);
                    }
                    if (Transitions[state].ContainsKey(u))
                    {
                        newStates.UnionWith(Transitions[state][u]);
                    }
                }
                currStates = newStates;
            }

            return(EndStates.Intersect(currStates).Count() > 0);
        }