예제 #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);
 }