public object Evaluate(string expression) { AntlrInputStream stream = new AntlrInputStream(expression); CalculatorLexer lexer = new CalculatorLexer(stream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); CalculatorParser parser = new CalculatorParser(tokenStream); var root = parser.expression(); object result = root.Accept(m_processor); return(result); }
private int EvaluateInput(string input) { CalculatorLexer lexer = new CalculatorLexer(new AntlrInputStream(input)); lexer.RemoveErrorListeners(); lexer.AddErrorListener(new ThrowingErrorListener <int>()); CalculatorParser parser = new CalculatorParser(new CommonTokenStream(lexer)); parser.RemoveErrorListeners(); parser.AddErrorListener(new ThrowingErrorListener <IToken>()); return(new CalculatorVisitor().Visit(parser.expression())); }