Ejemplo n.º 1
0
        public bool ChangeHeadOfRule(Grammar grammar)
        {
            for (var i = 0; i < NumberOfRetries; i++)
            {
                var rule = grammar.GetRandomRule();
                if (!rule.IsInitialRule()) continue; //do not change complements of schematic rules. (push/pop)

                if (rule.Production.Length > 1)
                {
                    var newRule = new Rule(rule);
                    newRule.HeadPosition = (rule.HeadPosition + 1)%rule.Production.Length;

                    if (grammar.AreHeadRelationsConsistent(newRule))
                    {
                        grammar.DeleteRule(rule);
                        grammar.AddRule(newRule);
                        return true;
                    }
                }
            }
            return false;
        }
Ejemplo n.º 2
0
 public bool DeleteRule(Grammar grammar)
 {
     var rule = grammar.GetRandomRule();
     grammar.DeleteRule(rule);
     return true;
 }