Example #1
0
        public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, CommonTokenStream unprocessedTokenStream, BaseErrorListener errorListener)
        {
            unprocessedTokenStream.Reset();
            var parser = new VBAConditionalCompilationParser(unprocessedTokenStream);

            parser.AddErrorListener(errorListener);
            VBAConditionalCompilationParser.CompilationUnitContext tree;
            try
            {
                parser.Interpreter.PredictionMode = PredictionMode.Sll;
                tree = parser.compilationUnit();
            }
            catch (ParsePassSyntaxErrorException syntaxErrorException)
            {
                var parsePassText = syntaxErrorException.ParsePass == ParsePass.CodePanePass
                    ? "code pane"
                    : "exported";
                Logger.Warn($"SLL mode failed while preprocessing the {parsePassText} version of module {moduleName} at symbol {syntaxErrorException.OffendingSymbol.Text} at L{syntaxErrorException.LineNumber}C{syntaxErrorException.Position}. Retrying using LL.");
                Logger.Debug(syntaxErrorException, "SLL mode exception");
                unprocessedTokenStream.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            catch (Exception exception)
            {
                Logger.Warn($"SLL mode failed while prprocessing module {moduleName}. Retrying using LL.");
                Logger.Debug(exception, "SLL mode exception");
                unprocessedTokenStream.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            return(tree);
        }
        protected override IParseTree Parse(ITokenStream tokenStream, PredictionMode predictionMode, IParserErrorListener errorListener)
        {
            var parser = new VBAConditionalCompilationParser(tokenStream);

            parser.Interpreter.PredictionMode = predictionMode;
            parser.AddErrorListener(errorListener);
            return(parser.compilationUnit());
        }
 private string Preprocess(string unprocessedCode)
 {
     SymbolTable<string, IValue> symbolTable = new SymbolTable<string, IValue>();
     var stream = new AntlrInputStream(unprocessedCode);
     var lexer = new VBALexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new VBAConditionalCompilationParser(tokens);
     parser.AddErrorListener(new ExceptionErrorListener());
     var evaluator = new VBAPreprocessorVisitor(symbolTable, new VBAPredefinedCompilationConstants(_vbaVersion));
     var tree = parser.compilationUnit();
     var expr = evaluator.Visit(tree);
     return expr.Evaluate().AsString;
 }
        private Tuple <SymbolTable <string, IValue>, IValue> Preprocess(string code)
        {
            SymbolTable <string, IValue> symbolTable = new SymbolTable <string, IValue>();
            var stream = new AntlrInputStream(code);
            var lexer  = new VBALexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new VBAConditionalCompilationParser(tokens);

            parser.AddErrorListener(new ExceptionErrorListener());
            var evaluator = new VBAPreprocessorVisitor(symbolTable, new VBAPredefinedCompilationConstants(7.01));
            var tree      = parser.compilationUnit();
            var expr      = evaluator.Visit(tree);

            return(Tuple.Create(symbolTable, expr.Evaluate()));
        }
Example #5
0
        private Tuple <SymbolTable <string, IValue>, IValue> Preprocess(string code)
        {
            SymbolTable <string, IValue> symbolTable = new SymbolTable <string, IValue>();
            var stream = new AntlrInputStream(code);
            var lexer  = new VBALexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new VBAConditionalCompilationParser(tokens);

            parser.ErrorHandler = new BailErrorStrategy();
            //parser.AddErrorListener(new ExceptionErrorListener());
            var tree        = parser.compilationUnit();
            var evaluator   = new VBAPreprocessorVisitor(symbolTable, new VBAPredefinedCompilationConstants(7.01), tree.start.InputStream, tokens);
            var expr        = evaluator.Visit(tree);
            var resultValue = expr.Evaluate();

            Debug.Assert(parser.NumberOfSyntaxErrors == 0);
            return(Tuple.Create(symbolTable, resultValue));
        }
Example #6
0
        public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, CommonTokenStream unprocessedTokenStream)
        {
            unprocessedTokenStream.Reset();
            var parser = new VBAConditionalCompilationParser(unprocessedTokenStream);

            parser.AddErrorListener(new ExceptionErrorListener()); // notify?
            VBAConditionalCompilationParser.CompilationUnitContext tree;
            try
            {
                parser.Interpreter.PredictionMode = PredictionMode.Sll;
                tree = parser.compilationUnit();
            }
            catch (Exception ex)
            {
                Logger.Warn(ex, "SLL mode failed in module {0}. Retrying using LL.", moduleName);
                unprocessedTokenStream.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            return(tree);
        }
        public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, string unprocessedCode)
        {
            var stream = new AntlrInputStream(unprocessedCode);
            var lexer  = new VBALexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new VBAConditionalCompilationParser(tokens);

            parser.AddErrorListener(new ExceptionErrorListener());
            VBAConditionalCompilationParser.CompilationUnitContext tree = null;
            try
            {
                parser.Interpreter.PredictionMode = PredictionMode.Sll;
                tree = parser.compilationUnit();
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, "SLL mode failed in module {0}. Retrying using LL.", moduleName);
                tokens.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            return(tree);
        }
 private Tuple<SymbolTable<string, IValue>, IValue> Preprocess(string code)
 {
     SymbolTable<string, IValue> symbolTable = new SymbolTable<string, IValue>();
     var stream = new AntlrInputStream(code);
     var lexer = new VBALexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new VBAConditionalCompilationParser(tokens);
     parser.AddErrorListener(new ExceptionErrorListener());
     var evaluator = new VBAPreprocessorVisitor(symbolTable, new VBAPredefinedCompilationConstants(7.01));
     var tree = parser.compilationUnit();
     var expr = evaluator.Visit(tree);
     return Tuple.Create(symbolTable, expr.Evaluate());
 }