public void GenerateInitialRulesFromDerivedRules() { if (!LandingSites.Any() || !Moveables.Any()) { return; } var initialRules = ruleNumberDictionary.Values.ToList(); var derivedRules = initialRules.Where(x => !x.IsInitialRule()).ToList(); var toRemove = derivedRules.ToList(); foreach (var item in toRemove) { DeleteRule(item); } }
public void GenerateDerivedRulesFromSchema() { if (!LandingSites.Any() || !Moveables.Any()) { return; } var toAdd = new List <Rule>(); foreach (var moveable in Moveables) { var pop1 = new Rule(1, moveable, new[] { Epsilon }, 0, 0); pop1.Name.Stack = new NonTerminalStack(moveable); toAdd.Add(pop1); foreach (var landingSiteNonTerminal in LandingSites) { var push = new Rule(1, landingSiteNonTerminal, new[] { moveable, landingSiteNonTerminal }, 1, 1); push.Name.Stack = new NonTerminalStack("."); push.Production[1].Stack = new NonTerminalStack("."); push.Production[1].Stack = push.Production[1].Stack.Push(moveable); toAdd.Add(push); } var pop2 = new Rule(1, "IP", new[] { moveable, "VP" }, 1, 1); pop2.Name.Stack = new NonTerminalStack("."); pop2.Name.Stack = pop2.Name.Stack.Push(moveable); pop2.Production[0].Stack = new NonTerminalStack(moveable); pop2.Production[1].Stack = new NonTerminalStack("."); toAdd.Add(pop2); } foreach (var item in toAdd) { AddRule(item); } }