Beispiel #1
0
        private void btn_test_word_Click(object sender, EventArgs e)
        {
            try
            {
                bool valid_word = automaton_from_file.validateWord(txt_test_word.Text, automaton_from_file.states[0]);

                if (automaton_from_file.is_pda)
                {
                    string stack = automaton_from_file.stack;
                    if (stack.Equals(""))
                    {
                        stack = "_";
                    }
                    valid_word = automaton_from_file.validatePushDownWord(txt_test_word.Text, stack, automaton_from_file.states[0]);
                }

                label_test_word_result.Text = valid_word ? "Yes" : "No";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        private void btn_open_file_Click(object sender, EventArgs e)
        {
            try
            {
                //ez_katka
                Parser parser = new Parser();
                if (parser.openFile())
                {
                    automaton_from_file = parser.getAutomation();

                    //enabling the buttons
                    if (automaton_from_file != null)
                    {
                        btn_transform_from_dfa.Enabled = true;
                        button1.Enabled       = true;
                        btn_test_word.Enabled = true;
                    }

                    Test test = parser.getTest();

                    label_is_dfa.Text = automaton_from_file.isDfa() ? "yes" : "no";

                    //generating the files
                    string file_name = "graph.dot";
                    automaton_from_file.generateAutomatonGraphVizDiagram(file_name);
                    automaton_from_file.generateAutomatonText("automaton.txt");

                    //test vectors from file
                    list_test_vectors_from_file.Items.Clear();
                    foreach (Word word in test.words)
                    {
                        list_test_vectors_from_file.Items.Add(word.toString());
                    }
                    // is dfa from file
                    list_test_vectors_from_file.Items.Add("is dfa:" + test.dfa);

                    //tests from program
                    list_test_vectors_from_program.Items.Clear();
                    foreach (Word word in test.words)
                    {
                        bool valid_word = automaton_from_file.validateWord(word.word, automaton_from_file.states[0]);

                        if (automaton_from_file.is_pda)
                        {
                            string stack = automaton_from_file.stack;
                            if (stack.Equals(""))
                            {
                                stack = "_";
                            }
                            valid_word = automaton_from_file.validatePushDownWord(word.word, stack, automaton_from_file.states[0]);
                        }

                        string test_string = "word: " + word.word + ", is accepted: " + valid_word;
                        list_test_vectors_from_program.Items.Add(test_string);
                    }
                    list_test_vectors_from_program.Items.Add("is dfa:" + automaton_from_file.isDfa());

                    //graphviz

                    // into a dot-format file
                    string new_file_name = file_name.Substring(0, file_name.Length - 4) + ".jpg";
                    //string locaiton = Directory.GetCurrentDirectory();
                    //creating and opening the image
                    Process process = new Process();
                    process.StartInfo.FileName       = ".\\Graphviz2.38\\bin\\dot.exe";
                    process.StartInfo.Arguments      = " -Tjpg " + file_name + " -o " + new_file_name;
                    process.StartInfo.CreateNoWindow = true;
                    process.EnableRaisingEvents      = true;
                    process.Exited += (sender1, e1) => openFile(sender1, e1, new_file_name);
                    process.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }