private void btnAccept_Click(object sender, EventArgs e) { String result = IsLanguageSelected(); if (result != "SELECCIONADOS") { statLbl.Text = result; } else { int languageAIndex = GetLanguageIndex(comboLanguageA.Text); int languageBIndex = -1;//that means, there's no language if (!unarySelected) { languageBIndex = GetLanguageIndex(comboLanguageB.Text); } Entities.Language languageA = Languages[languageAIndex], languageB = languageBIndex != -1 ? Languages[languageBIndex] : null; txtResult.Text = Operate(selectedOperation, languageA, languageB); } }
// Operations public String Operate(string operation, Entities.Language languageA, Entities.Language languageB) { String result = ""; //Right now, we will guess that only 2 languages are on the array if (operation.Equals(Entities.Language.UNION)) { result = (languageA + languageB).GetCharsets(); } else if (operation.Equals(Entities.Language.INTERSECTION)) { result = Entities.Language.Intersection(languageA, languageB).GetCharsets(); } else if (operation.Equals(Entities.Language.CONCATENATION)) { result = (Entities.Language.Concatenation(languageA, languageB)).GetCharsets(); } else if (operation.Equals(Entities.Language.DIFFERENCE)) { result = Entities.Language.Difference(languageA, languageB).GetCharsets(); } else if (operation.Equals(Entities.Language.SYM_DIFFERENCE)) { result = Entities.Language.SymetricDifference(languageA, languageB).GetCharsets(); } else if (operation.Equals(Entities.Language.COMPLEMENT)) { result = Entities.Language.Complement(languageA, Entities.Language.Universe(Languages, lastLanguageIndex)).GetCharsets(); } else if (operation.Equals(Entities.Language.POWER)) { result = Entities.Language.Power(languageA, (int)numericPower.Value).GetCharsets(); } else if (operation.Equals(Entities.Language.KLEENE_CLOSURE)) { result = Entities.Language.KleeneClosure(languageA, 3).GetCharsets(); } else { result = Entities.Language.PositiveKleeneClosure(languageA, 3).GetCharsets(); } return(result); }
private void InitComponents() { Alphabets = new List <Entities.Alphabet>(); Languages = new List <Entities.Language>(); lastAlphabetIndex = 3; lastLanguageIndex = 3; unarySelected = false; selectedOperation = ""; Entities.Language language1 = new Entities.Language("a,b,c,d,e,f,g,h,i,j,k".Split(',')), language2 = new Entities.Language("a,e,i,o,u".Split(',')), language3 = new Entities.Language("m,a,r,i,a".Split(',')); Languages.Add(language1); Languages.Add(language2); Languages.Add(language3); txtLanguages.Text += "A: " + Languages[0].ToString(); // 1 txtLanguages.Text += "\r\nB: " + Languages[1].ToString(); // 2 txtLanguages.Text += "\r\nC: " + Languages[2].ToString(); // 3 comboLanguageA.Items.Add("A"); comboLanguageA.Items.Add("B"); comboLanguageA.Items.Add("C"); comboLanguageA.Text = comboLanguageA.Items[0].ToString(); comboLanguageA.Text = comboLanguageA.Items[1].ToString(); comboLanguageA.Text = comboLanguageA.Items[2].ToString(); comboLanguageB.Items.Add("A"); comboLanguageB.Items.Add("B"); comboLanguageB.Items.Add("C"); comboLanguageB.Text = comboLanguageB.Items[0].ToString(); comboLanguageB.Text = comboLanguageB.Items[1].ToString(); comboLanguageB.Text = comboLanguageB.Items[2].ToString(); }