コード例 #1
0
 public bool Equals(Grammatica <T> other)
 {
     if (other == null)
     {
         return(false);
     }
     else if (this.ToString() == other.ToString() && this.startSymbool == other.startSymbool && this.productieRegels == other.productieRegels && this.alfabet == other.alfabet)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            statements.Clear();

            if (InputBox.Text == "")
            {
                return;
            }
            if (vanExpressie.Checked)
            {
                try
                {
                    Expressie expressie = new Expressie(InputBox.Text);
                    _outputNDFA = expressie.ToNDFA();

                    if (ToDFA.Checked)
                    {
                        OutputBox.Text = _outputNDFA.ToDFA().ToString();
                    }
                    if (ToNDFA.Checked)
                    {
                        OutputBox.Text = _outputNDFA.ToString();
                    }
                    if (ToReguliereGrammatica.Checked)
                    {
                        OutputBox.Text = _outputNDFA.ToReguliereGrammatica().ToString();
                    }

                    foreach (var t in _outputNDFA.eindToestanden)
                    {
                        //output += "node [shape = doublecircle]; " + t + " ;\n";
                    }

                    foreach (var t in _outputNDFA.toestanden)
                    {
                        EdgeStatement statement = EdgeStatement.For(t.vorigeToestand, t.volgendeToestand.Item1).Set("label", t.volgendeToestand.Item2.ToString());
                        statements.Add(statement);
                    }
                }
                catch (Exception exception)
                {
                    OutputBox.Text += "Het is niet gelukt\n" + exception.ToString();
                }
            }
            else if (vanDFA.Checked)
            {
                NDFA <char> ndfa = new NDFA <char>();
                for (int x = 0; x < InputBox.Lines.Count(); x++)
                {
                    string temp = InputBox.Lines[x];
                    if (temp.StartsWith("begin"))
                    {
                        ndfa.startSymbolen.Add(temp.Last().ToString());
                    }
                    else if (temp.StartsWith("eind"))
                    {
                        ndfa.eindToestanden.Add(temp.Last().ToString());
                    }
                    else
                    {
                        ndfa.toestanden.Add(Toestand <char> .CreateToestand(temp));
                    }
                    foreach (var t in ndfa.toestanden)
                    {
                        ndfa.invoerSymbolen.Add(t.volgendeToestand.Item2);
                    }
                }
                if (ToDFA.Checked)
                {
                    OutputBox.Text = ndfa.ToDFA().ToString();
                }
                if (ToNDFA.Checked)
                {
                    OutputBox.Text = ndfa.ToString();
                }
                if (ToReguliereGrammatica.Checked)
                {
                    OutputBox.Text = ndfa.ToReguliereGrammatica().ToString();
                }
                _outputNDFA = ndfa;

                foreach (var t in ndfa.toestanden)
                {
                    EdgeStatement statement = EdgeStatement.For(t.vorigeToestand, t.volgendeToestand.Item1).Set("label", t.volgendeToestand.Item2.ToString());
                    statements.Add(statement);
                }
            }
            else if (vanGrammatica.Checked)
            {
                if (ToNDFA.Checked)
                {
                    HashSet <ProductieRegel <char> > set = new HashSet <ProductieRegel <char> >();

                    for (int x = 0; x < InputBox.Lines.Count(); x++)
                    {
                        string[] temp         = InputBox.Lines[x].Split('-');
                        string   startSymbool = temp[0];
                        string   line         = temp[2].Substring(1);
                        string[] toestanden   = line.Split('|');

                        foreach (string s in toestanden)
                        {
                            string[] camelcase = SplitCamelCase(s);

                            if (camelcase.Length > 1)
                            {
                                set.Add(new ProductieRegel <char>(startSymbool, Convert.ToChar(camelcase[0]), camelcase[1]));
                            }
                            else
                            {
                                set.Add(new ProductieRegel <char>(startSymbool, Convert.ToChar(camelcase[0]), ""));
                            }
                        }
                    }

                    Grammatica <char> gr = new Grammatica <char>(InputBox.Lines.First().Split('-')[0], set);

                    OutputBox.Text = gr.TransformToNDFA().ToString();

                    foreach (var t in gr.TransformToNDFA().toestanden)
                    {
                        EdgeStatement statement = EdgeStatement.For(t.vorigeToestand, t.volgendeToestand.Item1).Set("label", t.volgendeToestand.Item2.ToString());
                        statements.Add(statement);
                    }
                }
            }
        }
コード例 #3
0
 public bool equals(Grammatica <T> other)
 {
     return(false);
 }