Exemplo n.º 1
0
        public void NfaTest()
        {
            var graph = new Graph("hello");

            graph.MarkEnd("kw_hello", "hello");

            var g2 = graph.Create("world");

            g2.MarkEnd("kw_world", "world");
            graph = graph.Union(g2);
            var logger = new ConsoleLogger("");

            var dfa    = graph.ToDfa(logger);
            var actual = new ScannerStateTable(dfa.States).Create();

            var expected = new[]
            {
                //  ▽ ⌀  o  l  e  h  d  r  w
                0, 0, 0, 0, 0, 1, 0, 0, 2, 0,  //0
                0, 0, 0, 0, 7, 0, 0, 0, 0, 0,  //1  'h'
                0, 0, 3, 0, 0, 0, 0, 0, 0, 0,  //2  'w'
                0, 0, 0, 0, 0, 0, 0, 4, 0, 0,  //3  'wo'
                0, 0, 0, 5, 0, 0, 0, 0, 0, 0,  //4  'wor'
                0, 0, 0, 0, 0, 0, 6, 0, 0, 0,  //5  'worl'
                2, 0, 0, 0, 0, 0, 0, 0, 0, 0,  //6  'world'
                0, 0, 0, 8, 0, 0, 0, 0, 0, 0,  //7  'he'
                0, 0, 0, 9, 0, 0, 0, 0, 0, 0,  //8  'hel'
                0, 0, 10, 0, 0, 0, 0, 0, 0, 0, //9  'hell'
                1, 0, 0, 0, 0, 0, 0, 0, 0, 0   //10 'hello'
            };

            var actualText = actual.ToText();

            Verify(expected, actual);

            actual = new ScannerStateTableWithSyntaxErrors(dfa.States).Create();
            //var expected2 = string.Join(",", map.OfType<int>().ToArray());
            expected = new[]
            {
                //  ▽ ⌀  o  l  e  h  d  r  w
                0, 11, 11, 11, 11, 1, 11, 11, 2, 11,
                0, 0, 0, 0, 7, 0, 0, 0, 0, 0,
                0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 4, 0, 0,
                0, 0, 0, 5, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 6, 0, 0, 0,
                2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 8, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 9, 0, 0, 0, 0, 0, 0,
                0, 0, 10, 0, 0, 0, 0, 0, 0, 0,
                1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                -1, 11, 11, 11, 11, 0, 11, 11, 0, 11
            };
            Verify(expected, actual);
        }
Exemplo n.º 2
0
 public IStateTableWriter CreateStateWriter(Dfa dfa, ScannerStateTable tableFactory) =>
 new UncompressedStateWriter(tableFactory);
Exemplo n.º 3
0
 public IStateTableWriter CreateStateWriter(Dfa dfa, ScannerStateTable tableFactory) =>
 new CompressStateWriter(dfa, tableFactory);