Beispiel #1
0
        static void Try(string input)
        {
            input = string.Concat(Enumerable.Repeat(input, 100000));
            if (show_input)
            {
                System.Console.WriteLine("Input:");
                System.Console.WriteLine(input);
            }

            DateTime before   = DateTime.Now;
            var      str      = new AntlrInputStream(input);
            var      lexer    = new SqlBaseLexer(str);
            var      tokens   = new CommonTokenStream(lexer);
            var      parser   = new SqlBaseParser(tokens);
            var      listener = new ErrorListener <IToken>(parser, lexer, tokens);

            parser.AddErrorListener(listener);
            lexer.AddErrorListener(new ErrorListener <int>(parser, lexer, tokens));
            var      tree  = parser.multipleStatement();
            DateTime after = DateTime.Now;

            if (listener.had_error)
            {
                System.Console.WriteLine("error in parse.");
            }
            else
            {
                System.Console.WriteLine("parse completed.");
            }
            if (show_tokens)
            {
                System.Console.WriteLine(tokens.OutputTokens(lexer));
            }
            if (show_tree)
            {
                System.Console.WriteLine(tree.OutputTree(tokens));
            }
            System.Console.WriteLine("time " + (after - before));
        }
Beispiel #2
0
        static void TryFile(string fn)
        {
            var str      = new UnbufferedCharStream(new StreamReader(fn));
            var lexer    = new AbcLexer(str);
            var tokens   = new UnbufferedTokenStream(lexer);
            var parser   = new AbcParser(tokens);
            var listener = new ErrorListener <IToken>(parser, lexer, tokens);

            parser.AddErrorListener(listener);
            lexer.AddErrorListener(new ErrorListener <int>(parser, lexer, tokens));
            parser.BuildParseTree = false;
            lexer.TokenFactory    = new MyCTF();
            var tree = parser.file();

            if (listener.had_error)
            {
                System.Console.WriteLine("error in parse.");
            }
            else
            {
                System.Console.WriteLine("parse completed.");
            }
        }