public void TestLF1() { Gramm gr = new Gramm(); gr.Terms.Add("i"); gr.Terms.Add("t"); gr.Terms.Add("l"); gr.Terms.Add("a"); gr.Terms.Add("b"); gr.NonTerms.Add("E"); gr.NonTerms.Add("S"); gr.St = "S"; gr.Rules.Add(new Rule("S", new List <string>() { "i", "E", "t", "S" })); gr.Rules.Add(new Rule("S", new List <string>() { "i", "E", "t", "S", "l", "S" })); gr.Rules.Add(new Rule("S", new List <string>() { "a" })); gr.Rules.Add(new Rule("E", new List <string>() { "b" })); Gramm newGr = GrammProcessor.RemoveLR(gr); newGr = FactProcessor.Fact(newGr); Assert.IsTrue(gr.NonTerms.Contains("S")); Assert.IsTrue(gr.NonTerms.Contains("E")); Assert.IsTrue(gr.NonTerms.Contains("S'")); Assert.AreEqual(5, gr.Rules.Count); Assert.AreEqual("iEtSS'", gr.Rules.Find(x => x.Left == "S" && x.Right != "a").Right); }
public void TestLF2() { Gramm gr = new Gramm(); gr.Terms.Add("a"); gr.Terms.Add("+"); gr.NonTerms.Add("A"); gr.NonTerms.Add("B"); gr.NonTerms.Add("C"); gr.NonTerms.Add("D"); gr.St = "A"; gr.Rules.Add(new Rule("A", new List <string>() { "a", "A" })); gr.Rules.Add(new Rule("A", new List <string>() { "+", "D" })); gr.Rules.Add(new Rule("A", new List <string>() { "D", "+" })); gr.Rules.Add(new Rule("B", new List <string>() { "B", "A" })); gr.Rules.Add(new Rule("B", new List <string>() { "C" })); gr.Rules.Add(new Rule("C", new List <string>() { "a", "A", "a" })); gr.Rules.Add(new Rule("C", new List <string>() { "B", "A", "+" })); gr.Rules.Add(new Rule("C", new List <string>() { "A", "a", "+" })); gr.Rules.Add(new Rule("D", new List <string>() { "B", "C" })); gr.Rules.Add(new Rule("D", new List <string>() { "a" })); gr.Rules.Add(new Rule("D", new List <string>() { "C" })); Gramm newGr = GrammProcessor.RemoveLR(gr); newGr = FactProcessor.Fact(newGr); Assert.IsTrue(gr.NonTerms.Contains("A")); Assert.IsTrue(gr.NonTerms.Contains("B")); Assert.IsTrue(gr.NonTerms.Contains("C")); Assert.IsTrue(gr.NonTerms.Contains("D")); Assert.IsTrue(gr.NonTerms.Contains("B'")); Assert.IsTrue(gr.NonTerms.Contains("D'''")); Assert.AreEqual(19, gr.Rules.Count); }