Esempio n. 1
0
 /// <summary>
 /// Parses independant math expressions and returns the result
 /// </summary>
 /// <param name="expr">String of expression</param>
 /// <param name="arrays">List of predetermined arrays</param>
 /// <returns>Single number</returns>
 public double ParseMathExpr(string expr, List <XArray> arrays)
 {
     foreach (Match m in Regex.Matches(expr, XSyntax.OpenTriangleBracket + "(.+?)" + XSyntax.CloseTriangleBracket))
     {
         expr = expr.Replace(XSyntax.OpenTriangleBracket + m.Groups[1].Value + XSyntax.CloseTriangleBracket, ParseMathExpr(m.Groups[1].Value, arrays).ToString());
     }
     return(xmParser.GetDouble(expr, 0, arrays));
 }
Esempio n. 2
0
 protected override double OverrideFunction(string[] parameters, XMParser xmParser, List <XArray> xarrs)
 {
     if (param)
     {
         double[] mparameters = new double[parameters.Length];
         for (int i = 0; i < parameters.Length; i++)
         {
             mparameters[i] = xmParser.GetDouble(parameters[i], 0, xarrs);
         }
         XArray array = new XArray(arrs[0], mparameters.Length);
         array.vars  = mparameters;
         array.level = 1;
         List <XArray> arrList = new List <XArray>();
         arrList.Add(array);
         return(xsParser.ParseReturnVariable(code, 1, arrList));
     }
     else
     {
         List <XArray> arrays = new List <XArray>();
         for (int i = 0; i < parameters.Length; i++)
         {
             int k = -1;
             for (int j = 0; j < xarrs.Count; j++)
             {
                 if (xarrs[j].name == parameters[i])
                 {
                     k = j;
                     break;
                 }
             }
             if (k != -1)
             {
                 arrays.Add(new XArray(arrs[i], xarrs[k].vars.Length));
                 arrays[arrays.Count - 1].vars  = xarrs[k].vars;
                 arrays[arrays.Count - 1].level = 1;
             }
         }
         return(xsParser.ParseReturnVariable(code, 1, arrays));
     }
 }
 protected override double OverrideFunction(string[] parameters, XMParser xmParser, List<XArray> xarrs)
 {
     if (param)
     {
         double[] mparameters = new double[parameters.Length];
         for (int i = 0; i < parameters.Length; i++)
             mparameters[i] = xmParser.GetDouble(parameters[i], 0, xarrs);
         XArray array = new XArray(arrs[0], mparameters.Length);
         array.vars = mparameters;
         array.level = 1;
         List<XArray> arrList = new List<XArray>();
         arrList.Add(array);
         return xsParser.ParseReturnVariable(code, 1, arrList);
     }
     else
     {
         List<XArray> arrays = new List<XArray>();
         for (int i = 0; i < parameters.Length; i++)
         {
             int k = -1;
             for (int j = 0; j < xarrs.Count; j++)
             {
                 if (xarrs[j].name == parameters[i])
                 {
                     k = j;
                     break;
                 }
             }
             if (k != -1)
             {
                 arrays.Add(new XArray(arrs[i], xarrs[k].vars.Length));
                 arrays[arrays.Count - 1].vars = xarrs[k].vars;
                 arrays[arrays.Count - 1].level = 1;
             }
         }
         return xsParser.ParseReturnVariable(code, 1, arrays);
     }
 }