/// <summary> /// Event handler for the calculate button. /// Parses and evaluates the input expression. /// If the expression was valid, the result are shown in the main list view. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCalculateExpression_Click(object sender, EventArgs e) { string expression = ReadExpression(); lstResultList.Items.Add(String.Format(">> {0}", expression)); //Calculate expression and add result to list RowEvaluator evaluator = new RowEvaluator(expression); //Try to parse and evaluate the expression. //Any errors are printed to the main list view. if (ParseExpression(evaluator) && EvaluateExpression(evaluator)) { try { PrintValue(evaluator.InterpretedExpression); } catch (Exception ex) { lstResultList.Items.Add(String.Format(" error: {0}", ex.Message)); } } AddExpressionToHistory(expression); lstResultList.Items.Add(String.Empty); UpdateGUI(); }
/// <summary> /// Tries to evaluate the input expression contained in the given evaluator. /// </summary> /// <param name="evaluator">The row evaluator with the given expression.</param> /// <returns>True if the evaluation was successfull.</returns> private bool EvaluateExpression(RowEvaluator evaluator) { try { evaluator.InterpretExpression(); return(true); } catch (Exception ex) { lstResultList.Items.Add(String.Format(" error: {0}", ex.Message)); return(false); } }
internal void Evaluate(out List <ExpressionItem> list) { Scanner scanner = new Scanner(scriptFileContents, Environment.NewLine); RowEvaluator rowEvaluator; list = new List <ExpressionItem>(); while (scanner.HasNext()) { rowEvaluator = new RowEvaluator(scanner.Next()); rowEvaluator.ParseExpression(); rowEvaluator.InterpretExpression(); list.Add(rowEvaluator.InterpretedExpression); } }