Пример #1
0
        public void HandTests(string code)
        {
            Console.Error.WriteLine("Example: ");
            Console.WriteLine(code);
            Console.WriteLine("Result: ");

            StreamWriter outputStreamWriter = new StreamWriter(Console.OpenStandardOutput());

            outputStreamWriter.AutoFlush = true;
            Console.SetOut(outputStreamWriter);

            var printer = new AstVisitor_Print();

            printer.Print(outputStreamWriter, ExecuteClosureRemover(code));
        }
Пример #2
0
        static void RemoveClosures(StreamReader codeReader, StreamWriter codeWriter)
        {
            AntlrInputStream     inputStream       = new AntlrInputStream(codeReader);
            LikeJavaScriptLexer  lexer             = new LikeJavaScriptLexer(inputStream);
            CommonTokenStream    commonTokenStream = new CommonTokenStream(lexer);
            LikeJavaScriptParser parser            = new LikeJavaScriptParser(commonTokenStream);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(ThrowingErrorListener.INSTANCE);

            var astBuilder     = new CstToAstVisitor();
            var ast            = astBuilder.Visit(parser.compileUnit()) as Node_FunctionDecl;
            var closureRemover = new ClosureRemover.ClosureRemover();

            closureRemover.RemoveClosures(ast);

            var printer = new AstVisitor_Print();

            printer.Print(codeWriter, ast);
        }