Exemplo n.º 1
0
 public static IEnumerable <(double, string)> EvaluateExpression(string exp)
 {
     try
     {
         Console.WriteLine($"Evaluating: {exp}");
         var inputStream = new AntlrInputStream(exp);
         var lexer       = new DiceLexer(inputStream);
         var tokenStream = new CommonTokenStream(lexer);
         var parser      = new DiceParser(tokenStream);
         var context     = parser.request();
         var evaluator   = new RequestEvaluator();
         return(evaluator.Visit(context));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(new[] { (0.0, "Failed to parse and evaluate") });