public MathFunction(string Name, string Code, bool Param, string[] Arrays, XSParser XsParser)
     : base(Name)
 {
     code = Code;
     arrs = Arrays;
     xsParser = XsParser;
     param = Param;
 }
Ejemplo n.º 2
0
 public MathFunction(string Name, string Code, bool Param, string[] Arrays, XSParser XsParser)
     : base(Name)
 {
     code     = Code;
     arrs     = Arrays;
     xsParser = XsParser;
     param    = Param;
 }
Ejemplo n.º 3
0
        public static bool BooleanExpression(string expr, List <XArray> arrays, XSParser parser)
        {
            string b     = "";
            int    ti    = 0;
            string eexpr = "";

            for (int i = 0; i < expr.Length; i++)
            {
                if (expr[i] == XSyntax.LogicAnd || expr[i] == XSyntax.LogicOr)
                {
                    eexpr = expr.Substring(ti, i - ti);
                    if (SingleBooleanExpression(eexpr, arrays, parser))
                    {
                        b += XSyntax.TrueWord;
                    }
                    else
                    {
                        b += XSyntax.FalseWord;
                    }
                    b += expr[i];
                    ti = i + 1;
                }
            }
            eexpr = expr.Substring(ti, expr.Length - ti);
            if (SingleBooleanExpression(eexpr, arrays, parser))
            {
                b += XSyntax.TrueWord;
            }
            else
            {
                b += XSyntax.FalseWord;
            }
            while (!(b == XSyntax.TrueWord || b == XSyntax.FalseWord))
            {
                b = b.Replace(XSyntax.TrueWord + XSyntax.LogicAnd + XSyntax.TrueWord, XSyntax.TrueWord);
                b = b.Replace(XSyntax.FalseWord + XSyntax.LogicAnd + XSyntax.FalseWord, XSyntax.FalseWord);
                b = b.Replace(XSyntax.TrueWord + XSyntax.LogicAnd + XSyntax.FalseWord, XSyntax.FalseWord);
                b = b.Replace(XSyntax.FalseWord + XSyntax.LogicAnd + XSyntax.TrueWord, XSyntax.FalseWord);
                b = b.Replace(XSyntax.TrueWord + XSyntax.LogicOr + XSyntax.TrueWord, XSyntax.TrueWord);
                b = b.Replace(XSyntax.FalseWord + XSyntax.LogicOr + XSyntax.FalseWord, XSyntax.FalseWord);
                b = b.Replace(XSyntax.TrueWord + XSyntax.LogicOr + XSyntax.FalseWord, XSyntax.TrueWord);
                b = b.Replace(XSyntax.FalseWord + XSyntax.LogicOr + XSyntax.TrueWord, XSyntax.TrueWord);
            }
            if (b == XSyntax.TrueWord)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static bool SingleBooleanExpression(string expr, List<XArray> arrays, XSParser parser)
        {
            char op = ' ';
            double left = 0f;
            double right = 0f;
            for (int i = 0; i < expr.Length; i++)
            {
                if (expr[i] == XSyntax.LogicEqual || expr[i] == XSyntax.LogicLarger || expr[i] == XSyntax.LogicSmaller || expr[i] == XSyntax.LogicNot)
                {
                    op = expr[i];
                    left = parser.ParseMathExpr(expr.Substring(0, i), arrays);
                    right = parser.ParseMathExpr(expr.Substring(i + 1), arrays);
                    break;
                }
            }

            if (op == XSyntax.LogicEqual)
            {
                if (left == right)
                    return true;
                return false;
            }
            else if (op == XSyntax.LogicSmaller)
            {
                if (left < right)
                    return true;
                return false;
            }
            else if (op == XSyntax.LogicLarger)
            {
                if (left > right)
                    return true;
                return false;
            }
            else if(op == XSyntax.LogicNot)
            {
                if(left != right)
                    return true;
                return false;
            }
            throw new XLogicException("Unknown operator.");
        }
Ejemplo n.º 5
0
 public static bool BooleanExpression(string expr, List<XArray> arrays, XSParser parser)
 {
     string b = "";
     int ti = 0;
     string eexpr = "";
     for (int i = 0; i < expr.Length; i++)
     {
         if (expr[i] == XSyntax.LogicAnd || expr[i] == XSyntax.LogicOr)
         {
             eexpr = expr.Substring(ti, i - ti);
             if (SingleBooleanExpression(eexpr, arrays, parser))
                 b += XSyntax.TrueWord;
             else
                 b += XSyntax.FalseWord;
             b += expr[i];
             ti = i + 1;
         }
     }
     eexpr = expr.Substring(ti, expr.Length - ti);
     if (SingleBooleanExpression(eexpr, arrays, parser))
         b += XSyntax.TrueWord;
     else
         b += XSyntax.FalseWord;
     while (!(b == XSyntax.TrueWord || b == XSyntax.FalseWord))
     {
         b = b.Replace(XSyntax.TrueWord + XSyntax.LogicAnd + XSyntax.TrueWord, XSyntax.TrueWord);
         b = b.Replace(XSyntax.FalseWord + XSyntax.LogicAnd + XSyntax.FalseWord, XSyntax.FalseWord);
         b = b.Replace(XSyntax.TrueWord + XSyntax.LogicAnd + XSyntax.FalseWord, XSyntax.FalseWord);
         b = b.Replace(XSyntax.FalseWord + XSyntax.LogicAnd + XSyntax.TrueWord, XSyntax.FalseWord);
         b = b.Replace(XSyntax.TrueWord + XSyntax.LogicOr + XSyntax.TrueWord, XSyntax.TrueWord);
         b = b.Replace(XSyntax.FalseWord + XSyntax.LogicOr + XSyntax.FalseWord, XSyntax.FalseWord);
         b = b.Replace(XSyntax.TrueWord + XSyntax.LogicOr + XSyntax.FalseWord, XSyntax.TrueWord);
         b = b.Replace(XSyntax.FalseWord + XSyntax.LogicOr + XSyntax.TrueWord, XSyntax.TrueWord);
     }
     if (b == XSyntax.TrueWord)
         return true;
     return false;
 }
Ejemplo n.º 6
0
 // A function that every process has to override
 protected virtual List <XArray> OverrideProcess(string code, List <XArray> arrs, XSParser parser, string[] cons, int codeLevel)
 {
     return(new List <XArray>());
 }
Ejemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code">String of code</param>
 /// <param name="arrs">Predetermined arrays</param>
 /// <param name="parser">Instance of script parser</param>
 /// <param name="boolean">The condition/expression of the process</param>
 /// <param name="codeLevel">The code level that the process is in</param>
 /// <returns>List of arrays</returns>
 public List <XArray> BeginProcess(string code, List <XArray> arrs, XSParser parser, string boolean, int codeLevel)
 {
     string[] cons = Helper.SplitOutOfBrackets(boolean, XSyntax.Comma, XSyntax.OpenRoundBracket, XSyntax.CloseRoundBracket);
     return(OverrideProcess(code, arrs, parser, cons, codeLevel));
 }
Ejemplo n.º 8
0
 protected virtual List<XArray> OverrideCommand(string[] parameters, XSParser parser, List<XArray> arrs)
 {
     return new List<XArray>();
 }
Ejemplo n.º 9
0
 public List<XArray> ProcessCommand(string t, XSParser parser, List<XArray> arrs)
 {
     string[] parameters = Helper.SplitOutOfBrackets(t, XSyntax.Comma, XSyntax.OpenRoundBracket, XSyntax.CloseRoundBracket);
     return OverrideCommand(parameters, parser, arrs);
 }
Ejemplo n.º 10
0
 protected virtual List <XArray> OverrideCommand(string[] parameters, XSParser parser, List <XArray> arrs)
 {
     return(new List <XArray>());
 }
Ejemplo n.º 11
0
 public List <XArray> ProcessCommand(string t, XSParser parser, List <XArray> arrs)
 {
     string[] parameters = Helper.SplitOutOfBrackets(t, XSyntax.Comma, XSyntax.OpenRoundBracket, XSyntax.CloseRoundBracket);
     return(OverrideCommand(parameters, parser, arrs));
 }
Ejemplo n.º 12
0
 protected virtual List<XArray> OverrideProcess(string code, List<XArray> arrs, XSParser parser, string[] cons, int codeLevel)
 {
     return new List<XArray>();
 }
Ejemplo n.º 13
0
 public List<XArray> BeginProcess(string code, List<XArray> arrs, XSParser parser, string boolean, int codeLevel)
 {
     string[] cons = Helper.SplitOutOfBrackets(boolean, XSyntax.Comma, XSyntax.OpenRoundBracket, XSyntax.CloseRoundBracket);
     return OverrideProcess(code, arrs, parser, cons, codeLevel);
 }
Ejemplo n.º 14
0
        public static bool SingleBooleanExpression(string expr, List <XArray> arrays, XSParser parser)
        {
            char   op    = ' ';
            double left  = 0f;
            double right = 0f;

            for (int i = 0; i < expr.Length; i++)
            {
                if (expr[i] == XSyntax.LogicEqual || expr[i] == XSyntax.LogicLarger || expr[i] == XSyntax.LogicSmaller || expr[i] == XSyntax.LogicNot)
                {
                    op    = expr[i];
                    left  = parser.ParseMathExpr(expr.Substring(0, i), arrays);
                    right = parser.ParseMathExpr(expr.Substring(i + 1), arrays);
                    break;
                }
            }

            if (op == XSyntax.LogicEqual)
            {
                if (left == right)
                {
                    return(true);
                }
                return(false);
            }
            else if (op == XSyntax.LogicSmaller)
            {
                if (left < right)
                {
                    return(true);
                }
                return(false);
            }
            else if (op == XSyntax.LogicLarger)
            {
                if (left > right)
                {
                    return(true);
                }
                return(false);
            }
            else if (op == XSyntax.LogicNot)
            {
                if (left != right)
                {
                    return(true);
                }
                return(false);
            }
            throw new XLogicException("Unknown operator.");
        }