//public WordDerivation[] LaterDerivations { get; set; } public WordDerivation(Rule rule, Word original, Word derived, WordDerivation previous) { Rule = rule; Original = original; Derived = derived; Previous = previous; }
public WordDerivation[] Derive(ExecutionContext context, Word word) { var originalDerivation = WordDerivation.Origin(word); var derivations = new WordDerivation[] { originalDerivation }; var newDerivations = new List <WordDerivation>(); foreach (var rule in Rules) { foreach (var derivation in derivations) { try { var results = rule.Derive(context, derivation); if (results.Length > 0) { newDerivations.AddRange(results); } else { newDerivations.Add(derivation); } } catch (Exception e) { throw new RuleException(rule, e); } } derivations = newDerivations.ToArray(); newDerivations.Clear(); } return(derivations.ToArray()); }