Ejemplo n.º 1
0
        public bool InsertRuleWithANewSymbol(Grammar grammar)
        {
            for (var i = 0; i < NumberOfRetries; i++)
            {
                var existingLHSNonTerminal = grammar.GetRandomRule().Name.NonTerminal;
                if (existingLHSNonTerminal == grammar.StartSymbol) continue;

                var newLHSNonTerminal = grammar.GetNextAvailableProjectionName();

                var typeOfExistingLHS = grammar.NonTerminalsTypeDictionary[existingLHSNonTerminal];

                grammar.AddProjectionTypeToTypeDictionary(newLHSNonTerminal, typeOfExistingLHS);

                //grammar.AddRule(new Rule(0, grammar.StartSymbol, new[] { newLHSNonTerminal, grammar.StartSymbol }, 0, 1));
                // grammar.AddRule(new Rule(0, grammar.StartSymbol, new[] { newLHSNonTerminal }, 0, 0));

                grammar.AddRule(new Rule(0, newLHSNonTerminal, new[] {existingLHSNonTerminal}, 0, 0));


                return true;
            }
            return false;
        }