public ComputeResult Compute(string input) { var streamInput = new AntlrInputStream(input); var lexer = new CurrencyComputerLexer(streamInput); lexer.RemoveErrorListeners(); lexer.AddErrorListener(new ErrorListener()); var tokens = new CommonTokenStream(lexer); var parser = new CurrencyComputerParser(tokens) { BuildParseTree = true }; parser.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION; var resultComputed = (Tuple <decimal, string>) new ComputerVisitor( _conversionsCost, _conversionToCurrencyConventions, _logger) .VisitInput(parser.input()); return(new ComputeResult { Currency = resultComputed.Item2, Value = resultComputed.Item1 }); }
public decimal Compute(string input) { var streamInput = new AntlrInputStream(input); var lexer = new CurrencyComputerLexer(streamInput); var tokens = new CommonTokenStream(lexer); var parser = new CurrencyComputerParser(tokens) { BuildParseTree = true }; parser.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION; var resultComputed = (decimal) new ComputerVisitor( _conversionsCost, _conversionToCurrencyConventions, _logger) .VisitInput(parser.input()); return(resultComputed); }