예제 #1
0
 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()));
        }
예제 #3
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));
        }
 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());
 }