Exemplo n.º 1
0
        public void testLanguage()
        {
            Console.WriteLine("taal van (baa):\n" + printSet(expr1.getLanguage(5)));
            Console.WriteLine("taal van (bb):\n" + printSet(expr2.getLanguage(5)));
            Console.WriteLine("taal van (baa | bb):\n" + printSet(expr3.getLanguage(5)));

            Console.WriteLine("taal van (a|b)*:\n" + printSet(all.getLanguage(5)));
            Console.WriteLine("taal van (baa | bb)+:\n" + printSet(expr4.getLanguage(5)));
            Console.WriteLine("taal van (baa | bb)+ (a|b)*:\n" + printSet(expr5.getLanguage(6)));
        }
Exemplo n.º 2
0
        private static void TestRegex(RegExp reg)
        {
            Console.WriteLine($"\n{reg.ToString()}");
            var automaat = Thompson.CreateAutomaat(reg);

            automaat.PrintTransitions();
            Console.WriteLine("alphabet:");
            foreach (var s in automaat.GetAlphabet())
            {
                Console.WriteLine(s);
            }
            Console.WriteLine("\ntalen die regex accepteert");
            foreach (var s in reg.getLanguage(3))
            {
                Console.WriteLine($"Taal:{s}, wordt geaccepteerd:{automaat.Accepteer(s)}\n");
            }
        }
Exemplo n.º 3
0
        public SortedSet <String> getLanguage(int maxSteps)
        {
            //compare by lenght?
            SortedSet <String> emptyLanguage  = new SortedSet <string>(new CompareByLength());
            SortedSet <String> languageResult = new SortedSet <string>(new CompareByLength());

            SortedSet <String> languageLeft, languageRight;

            if (maxSteps < 1)
            {
                return(emptyLanguage);
            }

            switch (this._operator)
            {
            case Operator.ONE:
                languageResult.Add(terminals);
                break;

            case Operator.OR:
                languageLeft  = left == null ? emptyLanguage : left.getLanguage(maxSteps - 1);
                languageRight = right == null ? emptyLanguage : right.getLanguage(maxSteps - 1);
                foreach (var l in languageLeft)
                {
                    languageResult.Add(l);
                }

                foreach (var r in languageRight)
                {
                    languageResult.Add(r);
                }
                break;


            case Operator.DOT:
                languageLeft  = left == null ? emptyLanguage : left.getLanguage(maxSteps - 1);
                languageRight = right == null ? emptyLanguage : right.getLanguage(maxSteps - 1);
                foreach (var s1 in languageLeft)
                {
                    foreach (var s2 in languageRight)
                    {
                        languageResult.Add(s1 + s2);
                    }
                }
                break;

            // STAR(*) en PLUS(+) kunnen we bijna op dezelfde manier uitwerken:
            case Operator.STAR:
            case Operator.PLUS:
                languageLeft = left == null ? emptyLanguage : left.getLanguage(maxSteps - 1);
                foreach (var l in languageLeft)
                {
                    languageResult.Add(l);
                }
                for (int i = 1; i < maxSteps; i++)
                {
                    HashSet <String> languageTemp = new HashSet <String>(languageResult);
                    foreach (var s1 in languageLeft)
                    {
                        foreach (var s2 in languageTemp)
                        {
                            languageResult.Add(s1 + s2);
                        }
                    }
                }
                if (this._operator == Operator.STAR)
                {
                    languageResult.Add("");
                }
                break;

            default:
                Console.WriteLine("getLanguage is nog niet gedefinieerd voor de operator: " + this._operator);
                break;
            }


            return(languageResult);
        }