public MathExpressions() { var first = new Expression(); Expressions.Add(first); _instance = this; }
public void Add() { var a = new Expression(); Expressions.Add(a); }
private void NotifyDependentExpressions(Expression source) { foreach (Expression e in dependentExpressions.ToList()) { e.ParseExpression(source); } }
public void RemoveDependentExpression(Expression e) { dependentExpressions.Remove(e); }
public void ParseExpression(Expression source = null) { try { if (!String.IsNullOrEmpty(Name) && Parser.PrimaryContext.AllVariables.ContainsKey(Name)) // Remove old value from parser { Parser.RemoveVariable(Name); } var parser = Parser.Parse(ExpressionString); var usedSymbols = parser.Context.Parser.CollectedSymbols; var dependsOn = MathExpressions.Instance.Expressions.Where(s => usedSymbols.Contains(s.Name)).ToList(); // Get expressions that are used by this expression. UpdateDependentOn(dependsOn); if (source == this) // Detecs infinite dependency loop. { Result = null; ErrorMessage = "Error. Infinite dependecy loop."; NotifyDependencyLoop(); return; } if (source == null) source = this; var result = parser.Execute(); if (!String.IsNullOrEmpty(Name)) // Variable must be named to be aded to parser { Parser.AddVariable(Name, result); } Result = result; ErrorMessage = null; NotifyDependentExpressions(source); } catch (Exception e) { ErrorMessage = e.Message; Result = null; NotifyDependentExpressions(source); } }
public void NotifyDependencyLoop(Expression source = null) { if (source == null || source != this) { if (source == null) source = this; Result = null; ErrorMessage = "Error. Infinite dependecy loop."; foreach (Expression e in dependentExpressions.ToList()) { e.NotifyDependencyLoop(source); } } }
public void AddDependentExpression(Expression e) { if (e != this && !dependentExpressions.Contains(e)) dependentExpressions.Add(e); }