Пример #1
0
        public void SkipGramarParseTest()
        {
            // get skip parse table
            Grammar skipGrammar    = GrammarParser.Parse(c_skipGrammar);
            var     skipParseTable = ParserTableConstructor.Construct(skipGrammar);
            var     skipGrammarStr = string.Join(Environment.NewLine, skipGrammar.Rules);
            var     skipTableStr   = new ParserTableFormatter().Format(skipParseTable);

            Console.Write(skipGrammarStr);
            Console.WriteLine();
            Console.Write(skipTableStr);
            Console.WriteLine();
            Console.WriteLine();

            var skipParser = new Parser(skipParseTable);

            skipParser.Parse("till 5 pm".Split(' '));
            skipParser.Parse("begin at 9 am and run to 5 pm nonstop".Split(' '));
        }
Пример #2
0
        public void NoSkipGramarParseTest()
        {
            // get non-skip parse table
            Grammar grammar    = GrammarParser.Parse(c_noSkipGrammar);
            var     parseTable = ParserTableConstructor.Construct(grammar);
            var     grammarStr = string.Join(Environment.NewLine, grammar.Rules);
            var     tableStr   = new ParserTableFormatter().Format(parseTable);

            Console.Write(grammarStr);
            Console.WriteLine();
            Console.Write(tableStr);
            Console.WriteLine();
            Console.WriteLine();

            var noSkipParser = new Parser(parseTable);

            noSkipParser.Parse("from 9 am".Split(' '));
            noSkipParser.Parse("begin from 9 am".Split(' '));
            noSkipParser.Parse("from 9 am finish".Split(' '));
        }