コード例 #1
0
        public void TestCFG_IntersectionWithRegexOptions()
        {
            var input = @"S -> \( S \) | (a)";
            ContextFreeGrammar cfg = ContextFreeGrammar.Parse(input);

            int    k = 5;
            string w;

            Assert.IsTrue(cfg.IntersectsWith(@"a.{" + k + "}", out w));

            var s = "";

            for (int i = 0; i < k; i++)
            {
                s += "(";
            }
            s += "a";
            for (int i = 0; i < k; i++)
            {
                s += ")";
            }

            Assert.AreEqual <string>(s, w);

            //determinization causes blowup of states in this case
            //will not terminate if determinization of regex is set to true, for large k
            Assert.IsTrue(cfg.IntersectsWith(@"a.{" + k + "}", out w, true));

            Assert.AreEqual <string>(s, w);
        }
コード例 #2
0
        public void TestCFG_EmptyRHS_check(ContextFreeGrammar cfg)
        {
            Assert.AreEqual("S", cfg.StartSymbol.Name);
            Assert.AreEqual(1, cfg.NonterminalCount);
            Assert.AreEqual(3, cfg.ProductionCount);

            string w;

            Assert.IsFalse(cfg.IntersectsWith(@"^x+a$", out w));
            Assert.IsTrue(cfg.IntersectsWith(@"^x+ay+$", out w));
            Assert.AreEqual <string>("xay", w);
        }
コード例 #3
0
        public void TestCFG_Intersect_Nontrivial()
        {
            var input = @"S -> \( S \) | [\w-[\d]]{3} | 0{2,}";
            ContextFreeGrammar cfg = ContextFreeGrammar.Parse(input);

            string w;

            Assert.IsFalse(cfg.IntersectsWith(@"^\((xy)+\)$", out w));
            Assert.IsTrue(cfg.IntersectsWith(@"^\({4}x+\)+$", out w));
            Assert.AreEqual <string>("((((xxx))))", w);
            Assert.IsTrue(cfg.IntersectsWith(@"^\(+0+\){7}$", out w));
            Assert.AreEqual <string>("(((((((00)))))))", w);
        }
コード例 #4
0
        public void TestCFG_Intersect()
        {
            //same as above but with a regex as a single terminal because there are no spaces between the sub-terminals
            //but outcome must be equivalent
            var input =
                @"S -> \( S \) | [abx][bxd][xde] 
";
            ContextFreeGrammar cfg = GrammarParser <BDD> .Parse(MkAutomaton, input);

            Assert.AreEqual("S", cfg.StartSymbol.Name);
            Assert.AreEqual(1, cfg.NonterminalCount);
            Assert.AreEqual(2, cfg.ProductionCount);

            string w;

            Assert.IsFalse(cfg.IntersectsWith(@"^\((xx)+\)$", out w));
            Assert.IsTrue(cfg.IntersectsWith(@"^\(x+\)$", out w));
            Assert.AreEqual <string>("(xxx)", w);
        }
コード例 #5
0
        public void TestCFG_MultipleRegexesAsTerminals()
        {
            var input = @"S -> \( S \) | \x20 | (cd) | (a+b+)";
            ContextFreeGrammar cfg = ContextFreeGrammar.Parse(input);

            Assert.IsTrue(cfg.NonterminalCount == 5);
            string w;

            Assert.IsTrue(cfg.IntersectsWith(@"\)", out w));
            Assert.AreEqual <string>("( )", w);
        }