Esempio n. 1
0
 public abstract void Visit(FunctionExpression function);
Esempio n. 2
0
        public string CalExpressionTreeResult(NCalc2.Expressions.LogicalExpression lgInput, int intSpaceInput)
        {
            if (lgInput == null)
            {
                return("\r\n");
            }
            //
            string strRet = "";
            string strTemp = "";
            int    i, j = 0;

            //Each time we call this function in another level, add more indication space
            int intSpace = intSpaceInput + 1;

            //
            if ((lgInput == null) || (lgInput.objResult == null)) //This one is Recursion stop condition
            {
                strRet = strRet + "null" + "\r\n";
            }
            else if (lgInput is NCalc2.Expressions.ValueExpression) //This one is Recursion stop condition
            {
                NCalc2.Expressions.ValueExpression ValueEx = (NCalc2.Expressions.ValueExpression)lgInput;
                strRet = strRet + lgInput.ToString() + ":" + ValueEx.Value.ToString() + "\r\n";
            }
            else if (lgInput is NCalc2.Expressions.IdentifierExpression) //This one is Recursion stop condition
            {
                strRet = strRet + lgInput.ToString() + ": " + lgInput.objResult.ToString() + "\r\n";
            }
            else if (lgInput is NCalc2.Expressions.FunctionExpression) //This case may do recursion
            {
                strRet = strRet + lgInput.ToString() + ": " + lgInput.objResult.ToString() + "\r\n";
                //
                NCalc2.Expressions.FunctionExpression FuncExpress = (NCalc2.Expressions.FunctionExpression)lgInput;
                for (j = 0; j < intSpace; j++)
                {
                    strTemp = strTemp + "___";
                }

                for (i = 0; i < FuncExpress.Expressions.Length; i++)
                {
                    strRet = strRet + strTemp + this.CalExpressionTreeResult(FuncExpress.Expressions[i], intSpace);// + "\r\n";
                }
            }
            else if (lgInput is NCalc2.Expressions.BinaryExpression) //This case may do recursion
            {
                NCalc2.Expressions.BinaryExpression BinaryEx = (NCalc2.Expressions.BinaryExpression)lgInput;
                strRet = strRet + lgInput.ToString() + ": " + lgInput.objResult.ToString() + "\r\n";
                for (j = 0; j < intSpace; j++)
                {
                    strTemp = strTemp + "___";
                }

                strRet = strRet + strTemp + this.CalExpressionTreeResult(BinaryEx.LeftExpression, intSpace);  // + "\r\n";
                strRet = strRet + strTemp + this.CalExpressionTreeResult(BinaryEx.RightExpression, intSpace); // + "\r\n";
            }
            else if (lgInput is NCalc2.Expressions.TernaryExpression)                                         //This case may do recursion
            {
                NCalc2.Expressions.TernaryExpression TernaryEx = (NCalc2.Expressions.TernaryExpression)lgInput;
                strRet = strRet + lgInput.ToString() + ": " + lgInput.objResult.ToString() + "\r\n";
                for (j = 0; j < intSpace; j++)
                {
                    strTemp = strTemp + "___";
                }

                strRet = strRet + strTemp + this.CalExpressionTreeResult(TernaryEx.LeftExpression, intSpace);   // + "\r\n";
                strRet = strRet + strTemp + this.CalExpressionTreeResult(TernaryEx.MiddleExpression, intSpace); // + "\r\n";
                strRet = strRet + strTemp + this.CalExpressionTreeResult(TernaryEx.RightExpression, intSpace);  // + "\r\n";
            }
            else if (lgInput is NCalc2.Expressions.UnaryExpression)                                             //This case may do recursion
            {
                NCalc2.Expressions.UnaryExpression UnaryEx = (NCalc2.Expressions.UnaryExpression)lgInput;
                strRet = strRet + lgInput.ToString() + ": " + lgInput.objResult.ToString() + "\r\n";
                for (j = 0; j < intSpace; j++)
                {
                    strTemp = strTemp + "___";
                }

                strRet = strRet + strTemp + this.CalExpressionTreeResult(UnaryEx.Expression, intSpace);// + "\r\n";
            }
            else //This one is Recursion stop condition
            {
                //strRet = strRet + lgInput.ToString() + ": " + lgInput.objResult.ToString() + "\r\n";
            }

            //
            return(strRet);
        }
Esempio n. 3
0
        public override void Visit(FunctionExpression function)
        {
            Result.Append(function.Identifier.Name);

            Result.Append("(");

            for (int i = 0; i < function.Expressions.Length; i++)
            {
                function.Expressions[i].Accept(this);
                if (i < function.Expressions.Length - 1)
                {
                    Result.Remove(Result.Length - 1, 1);
                    Result.Append(", ");
                }
            }

            // trim spaces before adding a closing paren
            while (Result[Result.Length - 1] == ' ')
                Result.Remove(Result.Length - 1, 1);

            Result.Append(") ");
        }