Beispiel #1
0
        public TestRegGram()
        {
            //Als N = { S, A }
            //    $ = { a, b }
            //P = { S -> bS, S -> aA, A -> bA, A -> b }
            //Dan is G = (N, $, P, S) een grammatica.

            char[] alphabet = { 'a', 'b' };
            var    RegGram  = new RegGram <string>(alphabet);

            RegGram.DefineStartSymbol("S");

            RegGram.AddProductionRule(new PRule <string>("S", alphabet[1], "S"));
            RegGram.AddProductionRule(new PRule <string>("S", alphabet[0], "A"));

            RegGram.AddProductionRule(new PRule <string>("A", alphabet[1], "A"));
            RegGram.AddProductionRule(new PRule <string>("A", alphabet[1]));

            Console.WriteLine(RegGram.ToString());
        }
Beispiel #2
0
        public static RegGram <T> NdfaToRegGram(Automaat <T> ndfa)
        {
            var regGram = new RegGram <T>(ndfa.GetAlphabet());

            foreach (var trans in ndfa._transitions)
            {
                regGram.AddProductionRule(new PRule <T>(trans.FromState, trans.Symbol, trans.ToState));
                if (ndfa._finalStates.Contains(trans.ToState))
                {
                    regGram.AddProductionRule(new PRule <T>(trans.FromState, trans.Symbol)
                    {
                        ToSymbolIsFinalSymbol = true
                    });
                }
            }

            regGram.DefineStartSymbol(ndfa._startStates.First());


            return(regGram);
        }