예제 #1
0
        //[Test]
        public void BigFile2()
        {
            Console.WriteLine("Starting BigFile");
            var code  = LoadTestCodeRaw();
            var lexer = new MalinaLexer(new AntlrInputStream(code));
            //lexer.RemoveErrorListeners();
            //lexer.ErrorListeners.Clear();
            var    t1    = Environment.TickCount;
            var    i     = 0;
            IToken token = null;

            for (token = lexer.NextToken(); token.Type != -1; token = lexer.NextToken())
            {
                i++;
            }
            var t2 = Environment.TickCount;

            Console.WriteLine("GetAllTokens Time: {0}", t2 - t1);
            Console.WriteLine("Token Number: {0}", i);
            Assert.Less(t2 - t1, 7000);

            lexer.Reset();
            var parser = MalinaParser.Create(new CommonTokenStream(lexer));

            parser.Interpreter.PredictionMode = PredictionMode.Sll;
            var malinaListener = new MalinaParserListener();

            //var parserErrorListener = new ErrorListener<IToken>();
            //parser.AddErrorListener(parserErrorListener);
            //parser.AddParseListener(malinaListener);
            parser.BuildParseTree = false;
            t1 = Environment.TickCount;
            //var module = parser.module();
            t2 = Environment.TickCount;

            Console.WriteLine("Parse Time: {0}", t2 - t1);
            Assert.Less(t2 - t1, 15000);
            //Assert.IsFalse(parserErrorListener.HasErrors);


            lexer.Reset();
            parser.Reset();
            parser.AddParseListener(malinaListener);
            t1 = Environment.TickCount;
            parser.module();
            lexer.Reset();
            parser.Reset();

            t2 = Environment.TickCount;
            Console.WriteLine("DOM Time: {0}", t2 - t1);
            Assert.Less(t2 - t1, 20000);
            //Assert.IsFalse(parserErrorListener.HasErrors);

            //t1 = Environment.TickCount;
            //var visitor = new DOMPrinterVisitor();
            //visitor.Visit(malinaListener.CompileUnit);
            //t2 = Environment.TickCount;
            //Console.WriteLine("Visitor Time: {0}", t2 - t1);
        }
예제 #2
0
        private static IList <IToken> GetTokens(string code, out MalinaLexer lexer, out ErrorListener <int> lexerErros)
        {
            lexer      = new MalinaLexer(new AntlrInputStream(code));
            lexerErros = new ErrorListener <int>();
            //lexer.RemoveErrorListeners();
            lexer.AddErrorListener(lexerErros);

            return(lexer.GetAllTokens());
        }
        private static void DoProcessAliasesAndNamespaces(string fileName, TextReader reader, CompilerContext context)
        {
            try
            {
                var lexer = new MalinaLexer(new AntlrInputStream(reader));

                lexer.RemoveErrorListeners();
                lexer.AddErrorListener(new LexerParserErrorListener <int>(context, fileName));

                var parser = MalinaParser.Create(new CommonTokenStream(lexer));
                parser.Interpreter.PredictionMode = PredictionMode.Sll;

                var resolvingListener = new AliasesAndNamespacesResolvingListener(context, fileName);

                parser.RemoveErrorListeners();
                parser.AddErrorListener(new LexerParserErrorListener <IToken>(context, fileName));
                parser.AddParseListener(resolvingListener);
                parser.module();
            }
            catch (Exception ex)
            {
                context.AddError(CompilerErrorFactory.FatalError(ex));
            }
        }