public void TestLine(string input, bool resolve = true)
        {
            // First, let's parse it
            CalcObject obj1 = CLInterpreter.Interpret(input);

            // And put it back to string and back
            string     code2 = obj1.ToCode();
            CalcObject obj3  = CLInterpreter.Interpret(code2);
            string     code4 = obj3.ToCode();

            // code2 and code4 need to match
            Assert.AreEqual(code2, code4, "code2 and code4 don't match on line: " + input);

            // We'll stop here if we're testing non-deterministic functions
            if (!resolve)
            {
                return;
            }

            // Then, let's get the value
            CalcValue  val5  = obj1.GetValue();
            string     code6 = val5.ToCode();
            CalcObject obj7  = CLInterpreter.Interpret(code6);
            string     code8 = obj7.ToCode();
            CalcValue  val9  = obj7.GetValue();

            // code6 and code8 need to match
            Assert.AreEqual(code6, code8, "code6 and code8 don't match on line: " + input);

            // val5 and val9 also need to match
            Assert.AreEqual(val5, val9, "val5 and val9 don't match on line: " + input);
        }
Exemple #2
0
        public string TestLine(string line, CLLocalStore vars, CLContextProvider context, string expected)
        {
            // We'll parse the line as usual
            CalcObject obj1  = CLInterpreter.Interpret(line);
            string     code2 = obj1.ToCode();
            CalcObject obj3  = CLInterpreter.Interpret(code2);
            string     code4 = obj3.ToCode();

            // Make sure things look right
            Assert.AreEqual(code2, code4);

            // Now get the value out of it
            CalcValue  val5  = obj3.GetValue(vars, context);
            string     code6 = val5.ToCode();
            CalcObject obj7  = CLInterpreter.Interpret(code6);
            string     code8 = val5.ToCode();
            CalcValue  val9  = obj7.GetValue(vars, context);

            // Make sure things still look right
            Assert.AreEqual(code6, code8);
            Assert.AreEqual(val5, val9);

            // Now we should also make sure the values reported are as expected.
            Assert.AreEqual(code8, expected);

            // And we'll return the final value so it can be used later!
            return(code8);
        }
Exemple #3
0
        // Concatenates two strings.
        public static CalcValue BinPlusStrings(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcString strLeft  = left as CalcString;
            CalcString strRight = right as CalcString;

            return(new CalcString(strLeft + strRight));
        }
Exemple #4
0
        private void CalculateAll()
        {
            string fromdate = "";
            string todate   = endtimeTB.Text;

            calObjectList.Clear();
            for (int i = 0; i < cfpCount; i++)
            {
                string barcode = cfpTable.Rows[i]["CFP_Barcode"].ToString();
                string date    = PersianDateTime.MiladiToShamsi(cfpTable.Rows[i]["CFP_Date"].ToString());

                //انتقال به جدول موقت برای مقایسه و فقط یکبار
                if (fromdate.Length == 0)
                {
                    fromdate = date;
                    helper.TransferPTableToTempTable(helper.GetPtableFromDate(fromdate));

                    helper.TransferPTableToTempTable(helper.GetPtableFromDate(todate));
                }

                CalcObject calcObj = new CalcObject();
                calcObj.barcode  = barcode;
                calcObj.fromDate = date;
                calcObj.toDate   = endtimeTB.Text;
                calObjectList.Add(calcObj);
            }
            if (fromdate.Length > 0)
            {
                helper.DeletePTable(helper.GetPtableFromDate(fromdate));
                helper.DeletePTable(helper.GetPtableFromDate(todate));

                helper.GTSCalculateAll(todate);
                timer1.Start();
            }
        }
        // Parses a parenthesized expression.
        private static CalcObject ParseParentheses(List <CLObjectPiece> pieces)
        {
            // First, get the "(" that spawned this method.
            CLObjectPiece lpar = pieces[0];

            pieces.RemoveAt(0);

            CalcObject ret = ParseChain(pieces);

            // If we now have an empty expression, we never closed the "(".
            if (pieces.Count == 0)
            {
                throw new CLSyntaxException("Unmatched (", lpar.Position);
            }
            else
            {
                // Otherwise, we should have a ")" next.
                CLObjectPiece rpar = pieces[0];
                pieces.RemoveAt(0);
                if (rpar.Contents != ")")
                {
                    // Maybe it's a "]", "}", or "," though.
                    throw new CLSyntaxException("Unmatched ( and " + rpar.Contents, lpar.Position);
                }
            }

            // But if we've made it here, we're fine.
            return(ret);
        }
Exemple #6
0
        private static CalcValue BinRepeat(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            List <CalcValue> ret      = new List <CalcValue>();
            CalcNumber       numRight = (CalcNumber)right;
            int count = (int)numRight.Value;

            CalcObject _i = null;

            if (vars.ContainsVar("_i"))
            {
                _i = vars["_i"];
            }

            for (int i = 0; i < count; i++)
            {
                vars["_i"] = new CalcNumber(i);
                ret.Add(left.GetValue(vars, context));
            }

            if (_i != null)
            {
                vars["_i"] = _i;
            }

            return(new CalcList(ret.ToArray()));
        }
Exemple #7
0
        // Adds two numbers.
        public static CalcValue BinPlusNumbers(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcNumber numLeft  = left as CalcNumber;
            CalcNumber numRight = right as CalcNumber;

            return(new CalcNumber(numLeft + numRight));
        }
Exemple #8
0
        // Returns the left raised to the power of the right.
        public static CalcValue BinPowerNumbers(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcNumber numLeft  = left as CalcNumber;
            CalcNumber numRight = right as CalcNumber;

            return(new CalcNumber((decimal)Math.Pow((double)(numLeft.Value), (double)(numRight.Value))));
        }
Exemple #9
0
        public static CalcValue BinIntDivideNumbers(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcNumber numLeft  = left as CalcNumber;
            CalcNumber numRight = right as CalcNumber;

            return(new CalcNumber(decimal.Floor(numLeft / numRight)));
        }
        /// <summary>Runs the Operator on two operands.</summary>
        /// <param name="left">The left operand.</param>
        /// <param name="right">The right operand.</param>
        /// <param name="vars">The local variable storage.</param>
        /// <param name="context">An object representing context.</param>
        public CalcValue Run(CalcObject left, CalcObject right, CLLocalStore vars = null, CLContextProvider context = null)
        {
            // If the operator is value-based, we'll automatically convert expressions.
            if (ValueBasedLeft)
            {
                left = left.GetValue(vars, context);
            }
            if (ValueBasedRight)
            {
                right = right.GetValue(vars, context);
            }

            // Now get the func.
            CLBinaryOperatorFunc func = this[left.GetType(), right.GetType()];

            // If it's null, we'll throw an exception.
            if (func == null)
            {
                throw new CLException(
                          "Binary operator " + Symbol + " doesn't support parameters " + left.GetType().Name + " and " + right.GetType().Name
                          );
            }

            // Now let's run it.
            return(func(left, right, vars, context));
        }
Exemple #11
0
        // Returns the string, reversed.
        public static CalcValue PreMinusString(CalcObject param, CLLocalStore vars, CLContextProvider context)
        {
            CalcString strParam = param as CalcString;

            char[] chars = strParam.Value.ToCharArray();
            Array.Reverse(chars);

            return(new CalcString(new string(chars)));
        }
        void FixedUpdate()
        {
            if (!blast)
            {
                return;
            }

            rb.AddForce(CalcObject.RotationToShotVector(transform.rotation.eulerAngles.z) * Power);
            blast = false;
        }
        // Parses a list.
        private static CalcListExpression ParseList(List <CLObjectPiece> pieces)
        {
            // First, get the "[" that spawned this method.
            CLObjectPiece lbracket = pieces[0];

            pieces.RemoveAt(0);

            List <CalcObject> ret = new List <CalcObject>();

            // Also, we'll allow empty lists.
            CLObjectPiece next = pieces[0];

            if (next.Contents == "]")
            {
                pieces.RemoveAt(0);
                return(new CalcListExpression(ret.ToArray()));
            }

            // But anyway, let's start populating non-empty lists.
            while (pieces.Count != 0)
            {
                // Get the value
                CalcObject obj = ParseChain(pieces);

                // But no empty values are allowed
                if (obj == null)
                {
                    throw new CLSyntaxException("Value expected in list", pieces[0].Position);
                }

                // Add it to the list
                ret.Add(obj);

                // Now get the next bracket
                next = pieces[0];
                pieces.RemoveAt(0);

                // If it's a ")" or "}", error.
                if (next.Contents == ")" || next.Contents == "}")
                {
                    throw new CLSyntaxException("Unclosed [ and " + next.Contents, lbracket.Position);
                }

                // If it's a "]", we're done.
                if (next.Contents == "]")
                {
                    return(new CalcListExpression(ret.ToArray()));
                }

                // Otherwise, keep looping.
            }

            // Oh, if we're out of pieces...
            throw new CLSyntaxException("Unclosed [", lbracket.Position);
        }
Exemple #14
0
        private void Calculate(object sender, Jacksonsoft.WaitWindowEventArgs e)
        {
            string fromdate = "";
            string todate   = "";

            if (endtimeTB.InvokeRequired)
            {
                calculatedTB.Invoke(new MethodInvoker(delegate { todate = endtimeTB.Text; }));
            }
            else
            {
                todate = endtimeTB.Text;
            }

            calObjectList.Clear();
            for (int i = 0; i < cfpCount; i++)
            {
                string barcode = cfpTable.Rows[i]["CFP_Barcode"].ToString();
                string date    = cfpTable.Rows[i]["CFP_Date"].ToString();

                //انتقال به جدول موقت برای مقایسه و فقط یکبار
                if (fromdate.Length == 0)
                {
                    fromdate = date;
                    helper.TransferPTableToTempTable(helper.GetPtableFromDate(fromdate));

                    helper.TransferPTableToTempTable(helper.GetPtableFromDate(todate));
                }

                GTS.Clock.AppSetup.DataSet.GTSDBTableAdapters.TA_PersonTableAdapter PersonTA = new GTS.Clock.AppSetup.DataSet.GTSDBTableAdapters.TA_PersonTableAdapter();
                decimal PersonId = (decimal)PersonTA.GetPrsID(barcode);

                helper.GTSCalculate(barcode, PersonId, date, todate);

                if (calculatedTB.InvokeRequired)
                {
                    calculatedTB.Invoke(new MethodInvoker(delegate { calculatedTB.Text += "- " + barcode; }));
                }
                else
                {
                    calculatedTB.Text += "- " + barcode;
                }
                //toolStripStatusLabel1.Text = String.Format("{0} of {1}", i + 1, cfpCount);
                e.Window.Message = String.Format("Calculating {0} of {1}", i + 1, cfpCount);
                CalcObject calcObj = new CalcObject();
                calcObj.barcode  = barcode;
                calcObj.fromDate = date;
                calcObj.toDate   = endtimeTB.Text;
                calObjectList.Add(calcObj);

                //toolStripStatusLabel1.Invalidate();
                //this.Invalidate();
                //this.Update();
            }
        }
Exemple #15
0
 // Converts a value to a number.
 internal static decimal ValueOf(CalcObject obj)
 {
     if (obj is CalcNumber num)
     {
         return(num.Value);
     }
     else
     {
         return((obj as CalcList).Sum());
     }
 }
        /// <summary>
        /// The method that turns a <c>List</c> of pieces into a full tree of
        ///   <c>CalcObject</c>s.
        /// </summary>
        /// <param name="pieces">The list of pieces.</param>
        public static CalcObject Parse(List <CLObjectPiece> pieces)
        {
            CalcObject obj = ParseChain(pieces);

            if (pieces.Count > 0)
            {
                CLObjectPiece piece = pieces[0];
                throw new CLSyntaxException("Unmatched " + piece.Contents, piece.Position);
            }

            return(obj);
        }
        public IActionResult Get(int calcId)
        {
            var calcObj = new CalcObject
            {
                CalcTime     = DateTime.Now,
                CalcBaseData = calcId,
            };

            this._queue.Enqueue(calcObj.CalcTask);

            return(this.Ok(calcId));
        }
        public static CalcValue PostFactNumber(CalcObject param, CLLocalStore vars, CLContextProvider context)
        {
            CalcNumber num = param as CalcNumber;
            int        o   = 1;

            for (int i = 2; i < num.Value; i++)
            {
                o *= i;
            }

            return(new CalcNumber(o));
        }
Exemple #19
0
        private void Compaire()
        {
            helper.InitTA_PTable();

            DataSet.DBDataSetTableAdapters.TA_CompaireDiffrenceTableAdapter cdTA = new DataSet.DBDataSetTableAdapters.TA_CompaireDiffrenceTableAdapter();
            cdTA.Connection = GTSAppSettings.SQLConnection;
            for (int k = 0; k < calObjectList.Count; k++)
            {
                CalcObject objcet = calObjectList[k];

                DBDataSet.TA_PTableUsableColumnsDataTable ta_ptable = new DBDataSet.TA_PTableUsableColumnsDataTable();
                DataSet.DBDataSetTableAdapters.TA_PTableUsableColumnsTableAdapter ptableTA = new DataSet.DBDataSetTableAdapters.TA_PTableUsableColumnsTableAdapter();
                ptableTA.Connection = GTSAppSettings.SQLConnection;
                ptableTA.Fill(ta_ptable);

                DBDataSet.TA_PTableUsableColumnsDataTable ptable1 = helper.GetPTableUsableColumns(objcet.barcode, objcet.fromDate, objcet.toDate, "Clock6", true);

                DBDataSet.TA_PTableUsableColumnsDataTable ptable2 = helper.GetPTableUsableColumns(objcet.barcode, objcet.fromDate, objcet.toDate, "GTS", false);

                DBDataSet.TA_PTableUsableColumnsDataTable ptable = helper.AppendPTable(ptable1, ptable2);

                string monthDate = objcet.toDate;
                monthDate  = monthDate.Remove(monthDate.Length - 2, 2);
                monthDate += "00";

                ptable.DefaultView.Sort = "prc_date";
                ta_ptable = helper.AppendPTable(ta_ptable, ptable.DefaultView);

                bool[,] deffMat = helper.GetDifferenceIndex(ta_ptable, objcet.barcode);
                int diffCount     = 0;
                int difMonthCount = 0;
                for (int i = 1; i < deffMat.GetLength(0); i++)
                {
                    for (int j = 0; j < deffMat.GetLength(1) - 1; j++)
                    {
                        if ((ta_ptable.Rows[i][1].ToString() == monthDate) && (j == 2 || j == 3 || j == 4 || j == 21))
                        {
                            continue;
                        }
                        if (ta_ptable.Rows[i][1].ToString() == monthDate && deffMat[i, j])
                        {
                            difMonthCount++;
                        }
                        if (deffMat[i, j])
                        {
                            diffCount++;
                        }
                    }
                }
                diffCount = diffCount / 2;
                cdTA.Insert(objcet.barcode, diffCount, difMonthCount, objcet.fromDate, objcet.toDate);
            }
        }
Exemple #20
0
        // Returns the list, with all its elements negated.
        public static CalcValue PreMinusList(CalcObject param, CLLocalStore vars, CLContextProvider context)
        {
            CalcList lstParam = param as CalcList;

            CalcValue[] lstRet = new CalcValue[lstParam.Count];

            for (int i = 0; i < lstRet.Length; i++)
            {
                lstRet[i] = PrefixMinus.Run(lstParam[i], vars, context);
            }

            return(new CalcList(lstRet));
        }
Exemple #21
0
        void Update()
        {
            if (targetLock == null)
            {
                return;
            }

            Vector2 direction = targetLock.position - transform.position;

            transform.rotation = CalcObject.VectorToRotationSlerp(
                transform.rotation, direction, TargetingSpeed
                );
        }
Exemple #22
0
        /// <summary>
        /// Saves a <c>CalcObject</c> as a variable.
        /// </summary>
        /// <param name="name">The name of the variable to save.</param>
        /// <param name="val">The value to save.</param>
        /// <param name="context">
        /// An object representing the context in which it's run.
        /// </param>
        public static void Save(string name, CalcObject val, CLContextProvider context)
        {
            CLVariableSave data = new CLVariableSave()
            {
                Name  = name,
                Value = val
            };

            VariableSaved.Invoke(context, data);

            if (!data.Saved)
            {
                InternalStorage[name] = val;
            }
        }
Exemple #23
0
        public IEnumerator OnLaserCollision(CollisionArgs sender)
        {
            float force = 75 * sender.damage;

            Vector2 forceAngle = CalcObject.AngleToAddForce(sender.point, gameObject.transform.position, force
                                                            );

            body.AddForce(forceAngle);

            if (!scream.isPlaying)
            {
                float maxPan = 33;
                scream.panStereo = transform.position.x / maxPan;
                scream.Play();
            }
            yield return(null);
        }
Exemple #24
0
        // Returns the quotient of a list's items over a number.
        public static CalcValue BinDivideList(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcList   lstLeft  = left as CalcList;
            CalcNumber numRight = right as CalcNumber;

            // We will *not* do string checking here
            // It's entirely possible someone writes a string divider and this function will use it.

            CalcValue[] lstRet = new CalcValue[lstLeft.Count];

            for (int i = 0; i < lstRet.Length; i++)
            {
                lstRet[i] = BinaryDivide.Run(lstLeft[i], numRight, vars, context);
            }

            return(new CalcList(lstRet));
        }
Exemple #25
0
        // Multiplies a string by a number.
        public static CalcValue BinTimesString(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcString strLeft  = left as CalcString;
            CalcNumber numRight = right as CalcNumber;

            int count = (int)numRight;

            if (count < 0)
            {
                throw new CLException("Strings cannot be repeated negative times.");
            }

            string strRet = "";

            for (int i = 0; i < count; i++)
            {
                strRet += strLeft;
            }

            return(new CalcString(strRet));
        }
Exemple #26
0
        // Concatenates two lists.
        public static CalcValue BinPlusLists(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcList lstLeft  = left as CalcList;
            CalcList lstRight = right as CalcList;

            CalcValue[] lstRet = new CalcValue[lstLeft.Count + lstRight.Count];

            int i;

            for (i = 0; i < lstLeft.Count; i++)
            {
                lstRet[i] = lstLeft[i];
            }

            for (int j = 0; j < lstRight.Count; j++)
            {
                lstRet[i + j] = lstRight[j];
            }

            return(new CalcList(lstRet));
        }
        /// <summary>Runs the Operator on two operands.</summary>
        /// <param name="param">The right operand.</param>
        /// <param name="vars">The local variable storage.</param>
        /// <param name="context">An object representing context.</param>
        public CalcValue Run(CalcObject param, CLLocalStore vars = null, CLContextProvider context = null)
        {
            // If the operator is value-based, we'll automatically convert expressions.
            if (ValueBased)
            {
                param = param.GetValue(vars, context);
            }

            // Now get the func.
            CLUnaryOperatorFunc func = this[param.GetType()];

            // If it's null, we'll throw an exception.
            if (func == null)
            {
                throw new CLException(
                          "Binary operator " + Symbol + " doesn't support parameter " + param.GetType().Name
                          );
            }

            // Now let's run it.
            return(func(param, vars, context));
        }
Exemple #28
0
        // Multiplies a list by a number.
        public static CalcValue BinTimesList(CalcObject left, CalcObject right, CLLocalStore vars, CLContextProvider context)
        {
            CalcList   lstLeft  = left as CalcList;
            CalcNumber numRight = right as CalcNumber;

            // If it has a string, we'll just repeat the list multiple times.
            if (lstLeft.HasString())
            {
                int count = (int)numRight;
                if (count < 0)
                {
                    throw new CLException("Lists cannot be repeated negative times.");
                }

                CalcValue[] lstRet = new CalcValue[lstLeft.Count * count];

                for (int i = 0; i < count; i++)
                {
                    for (int j = 0; j < lstLeft.Count; j++)
                    {
                        lstRet[i * lstLeft.Count + j] = lstLeft[j];
                    }
                }

                return(new CalcList(lstRet));
            }
            else
            {
                // Otherwise we'll multiply everything by the number.
                CalcValue[] lstRet = new CalcValue[lstLeft.Count];

                for (int i = 0; i < lstRet.Length; i++)
                {
                    lstRet[i] = BinaryTimes.Run(lstLeft[i], numRight, vars, context);
                }
                return(new CalcList(lstRet));
            }
        }
Exemple #29
0
        private static CalcValue KeepCompare(CalcObject left, CLComparison comp, CalcObject right, CLLocalStore vars)
        {
            CalcList   lstLeft  = (CalcList)left;
            CalcNumber numRight = (CalcNumber)right;

            List <CalcValue> kept    = new List <CalcValue>();
            List <CalcValue> dropped = new List <CalcValue>();

            foreach (CalcValue val in lstLeft)
            {
                if (comp.CompareFunction(ValueOf(val), numRight.Value))
                {
                    kept.Add(val);
                }
                else
                {
                    dropped.Add(val);
                }
            }

            vars["_d"] = new CalcList(dropped.ToArray());
            return(new CalcList(kept.ToArray()));
        }
        // And this method parses Functions, including Code Functions.
        private static CalcFunction ParseFunction(List <CLObjectPiece> pieces)
        {
            // As with the other two methods, we'll get and store the opener.
            CLObjectPiece lbrace = pieces[0];

            pieces.RemoveAt(0);

            string opener = lbrace.Contents;

            List <CalcObject> pars    = new List <CalcObject>();
            Match             mtcName = rgxName.Match(opener);
            string            name    = mtcName.Groups[1].Value;

            // And again, no-param functions are allowed.
            CLObjectPiece next = pieces[0];

            if (next.Contents == "}")
            {
                pieces.RemoveAt(0);
                return(new CalcFunction(name, pars.ToArray()));
            }

            // If the next piece is a comma, let's just get rid of it.
            if (next.Contents == ",")
            {
                pieces.RemoveAt(0);
            }

            // And parse through the params.
            while (pieces.Count != 0)
            {
                // Get the value
                CalcObject obj = ParseChain(pieces);

                // But no empty values are allowed
                if (obj == null)
                {
                    throw new CLSyntaxException("Value expected in function", pieces[0].Position);
                }

                // Add it to the params
                pars.Add(obj);

                // Now get the next bracket
                next = pieces[0];
                pieces.RemoveAt(0);

                // If it's a ")" or "]", error.
                if (next.Contents == ")" || next.Contents == "]")
                {
                    throw new CLSyntaxException("Unclosed { and " + next.Contents, lbrace.Position);
                }

                // If it's a "}", we're done.
                if (next.Contents == "}")
                {
                    return(new CalcFunction(name, pars.ToArray()));
                }

                // Otherwise, keep looping.
            }

            // Oh, if we're out of pieces...
            throw new CLSyntaxException("Unclosed {", lbrace.Position);
        }