Пример #1
0
 public MathExpressions()
 {
     var first = new Expression();
     Expressions.Add(first);
     _instance = this;
 }
Пример #2
0
 public void Add()
 {
     var a = new Expression();
     Expressions.Add(a);
 }
Пример #3
0
 private void NotifyDependentExpressions(Expression source)
 {
     foreach (Expression e in dependentExpressions.ToList())
     {
         e.ParseExpression(source);
     }
 }
Пример #4
0
 public void RemoveDependentExpression(Expression e)
 {
     dependentExpressions.Remove(e);
 }
Пример #5
0
 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);
     }
 }
Пример #6
0
 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);
         }
     }
 }
Пример #7
0
 public void AddDependentExpression(Expression e)
 {
     if (e != this && !dependentExpressions.Contains(e))
         dependentExpressions.Add(e);
 }