示例#1
0
        public void SubsetConstruction_Precidence()
        {
            var graphBuilder = new Graph.Builder();

            NFAHelper.Graph(
                graphBuilder,
                NFAHelper.Series <NodeData, CharSet>(
                    graphBuilder,
                    NFAHelper.CreateSimplePath(graphBuilder, '1'),
                    NFAHelper.CreateSimplePath(graphBuilder, '2'),
                    NFAHelper.CreateSimplePath(graphBuilder, '3'),
                    NFAHelper.CreateSimplePath(graphBuilder, '4')),
                NFAHelper.Repeat(
                    graphBuilder,
                    NFAHelper.CreateSimplePath(graphBuilder, '0', '9')));

            var dfaGraph = FATools.CreateDfa(graphBuilder.Graph);

            const string expected =
                "0 (S:S0) -- [0,2-9] --> 1 (L:E1)\r\n" +
                "0 (S:S0) -- [1] --> 2 (L:E1)\r\n" +
                "1 (L:E1) -- [0-9] --> 1 (L:E1)\r\n" +
                "2 (L:E1) -- [0-1,3-9] --> 1 (L:E1)\r\n" +
                "2 (L:E1) -- [2] --> 3 (L:E1)\r\n" +
                "3 (L:E1) -- [0-2,4-9] --> 1 (L:E1)\r\n" +
                "3 (L:E1) -- [3] --> 4 (L:E1)\r\n" +
                "4 (L:E1) -- [4] --> 5 (L:E0)\r\n" +
                "4 (L:E1) -- [0-3,5-9] --> 1 (L:E1)\r\n" +
                "5 (L:E0) -- [0-9] --> 1 (L:E1)\r\n" +
                "";

            Assert.That(FARenderer.Render(dfaGraph), Is.EqualTo(expected));
        }
示例#2
0
        public void SubsetConstruction_String()
        {
            var nfaBuilder = new Graph.Builder();

            NFAHelper.Graph(
                nfaBuilder,
                NFAHelper.Series(
                    nfaBuilder,
                    NFAHelper.CreateSimplePath(nfaBuilder, '"'),
                    NFAHelper.Optional(
                        nfaBuilder,
                        NFAHelper.Repeat(
                            nfaBuilder,
                            NFAHelper.Parallell(
                                nfaBuilder,
                                NFAHelper.Series(
                                    nfaBuilder,
                                    NFAHelper.CreateSimplePath(nfaBuilder, '"'),
                                    NFAHelper.CreateSimplePath(nfaBuilder, '"')),
                                NFAHelper.CreateSimplePath(nfaBuilder, '"', true)))),
                    NFAHelper.CreateSimplePath(nfaBuilder, '"')));

            var dfaGraph = FATools.CreateDfa(nfaBuilder.Graph);

            const string expected =
                "0 (S:S0) -- [\"] --> 1\r\n" +
                "1 -- [\"] --> 2 (L:E0)\r\n" +
                "1 -- ![\"] --> 1\r\n" +
                "2 (L:E0) -- [\"] --> 1\r\n" +
                "";

            Assert.That(FARenderer.Render(dfaGraph), Is.EqualTo(expected));
        }
示例#3
0
        public void SubsetConstruction_Label()
        {
            var nfaGraphBuilder = new Graph.Builder();

            var lead = new CharRange[] { new CharRange('A', 'Z'), new CharRange('a', 'z') };
            var tail = new CharRange[] { new CharRange('A', 'Z'), new CharRange('a', 'z'), new CharRange('0', '9'), new CharRange('_', '_') };

            NFAHelper.Graph(
                nfaGraphBuilder,
                NFAHelper.Series(
                    nfaGraphBuilder,
                    NFAHelper.CreateSimplePath(nfaGraphBuilder, CharSet.New(lead)),
                    NFAHelper.Optional(
                        nfaGraphBuilder,
                        NFAHelper.Repeat(
                            nfaGraphBuilder,
                            NFAHelper.CreateSimplePath(nfaGraphBuilder, CharSet.New(tail))))));

            var dfaGraph = FATools.CreateDfa(nfaGraphBuilder.Graph);

            const string expected =
                "0 (S:S0) -- [A-Z,a-z] --> 1 (L:E0)\r\n" +
                "1 (L:E0) -- [0-9,A-Z,_,a-z] --> 1 (L:E0)\r\n" +
                "";

            Assert.That(FARenderer.Render(dfaGraph), Is.EqualTo(expected));
        }