Пример #1
0
        public void CreateTextFile()
        {
            ListWords = ListWords.Distinct(new WordComparer()).ToList();
            string content = "";

            content += $"# {Comment}" + Environment.NewLine + Environment.NewLine;
            content += $"alphabet: {String.Join("", ListAlphabets)}" + Environment.NewLine;
            content += $"stack: {String.Join("", ListStacks)}" + Environment.NewLine;
            content += $"states: {String.Join(",", ListStates)}" + Environment.NewLine;
            content += $"final: {String.Join(",", ListStates.FindAll(x => x.IsFinal))}" + Environment.NewLine + Environment.NewLine;
            content += $"transitions:" + Environment.NewLine;
            content += $"{String.Join(Environment.NewLine, ListTransitions)}" + Environment.NewLine;
            content += "end." + Environment.NewLine + Environment.NewLine;
            content += "dfa: ";
            if (IsDFA)
            {
                content += "y" + Environment.NewLine;
            }
            else
            {
                content += "n" + Environment.NewLine;
            }
            content += "finite: ";
            if (IsFinite)
            {
                content += "y" + Environment.NewLine;
            }
            else
            {
                content += "n" + Environment.NewLine;
            }
            content += Environment.NewLine;
            content += $"words:" + Environment.NewLine;
            foreach (Word word in ListWords)
            {
                if (word.IsAccepted)
                {
                    content += word.Words + ",y" + Environment.NewLine;
                }
                else
                {
                    content += word.Words + ",n" + Environment.NewLine;
                }
            }
            content += "end.";
            string file_name = "automaton_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt";

            File.WriteAllText(file_name, content);
        }
Пример #2
0
        private Automaton ConvertToDFAWithoutEpsilonMove(List <State> states, List <Transition> transitions, State Sink)
        {
            List <State> initial_states = ListStates.FindAll(x => x.IsInitial);

            foreach (var initial in initial_states)
            {
                List <State> listini = new List <State>();
                listini.Add(initial);
                if (listini.Exists(x => x.IsFinal))
                {
                    initial.IsFinal = true;
                }
                states.Add(initial);
                ProcessDFA(listini, states, transitions, Sink, initial);
            }
            return(new Automaton(ListAlphabets, states, transitions, null, null));
        }
Пример #3
0
        private bool CheckIsFinite()
        {
            words   = new List <string>();
            hasLoop = false;
            List <State> initial_States = ListStates.FindAll(x => x.IsInitial);

            foreach (var initial in initial_States)
            {
                List <Transition> used_transitions = new List <Transition>();
                bool hasloop = false;
                GetWord(initial, used_transitions, hasloop);
            }
            if (hasLoop)
            {
                return(false);
            }
            foreach (var item in words)
            {
                ListWords.Add(new Word(item));
            }
            return(true);
        }