private static double?Parse(string question) { if (VariableExpression.IsMatch(question)) { KeyValuePair <string, double> variable = VariableExpression.Parse(question); MathExpression.AddVariable(variable.Key, variable.Value); return(variable.Value); } else if (PercentOfExpression.IsMatch(question)) { return(PercentOfExpression.Parse(question)); } else if (PercentOffExpression.IsMatch(question)) { return(PercentOffExpression.Parse(question)); } else if (MathExpression.IsMatch(question)) { return(MathExpression.Parse(question)); } else { return(null); } }
public static bool IsMatch(string expression) { if (!Regex.IsMatch(expression, REGEX_PATTERN)) { return(false); } int index = expression.IndexOf("=") + 1; string parsedExpression = expression.Substring(index).Trim(); return(MathExpression.IsMatch(parsedExpression)); }
public static string[] Parse(string[] questions) { MathExpression.Reset(); var answers = new string[questions.Length]; for (int i = 0; i < questions.Length; i++) { double?answer = Parse(questions[i]); answers[i] = answer.ToString(); if (answer != null) { MathExpression.AddVariable("line" + (i + 1), answer.Value); } } return(answers); }
public static KeyValuePair <string, double> Parse(string expression) { string[] parts = expression.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); return(new KeyValuePair <string, double>(parts[0].Trim(), MathExpression.Parse(parts[1].Trim()))); }