Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Evaluator" /> class.
 /// </summary>
 /// <param name="Tokens">The tokens.</param>
 public Evaluator(Parser.Token Tokens)
 {
     token = Tokens;
 }
Example #2
0
        private bool Eval(Parser.TokenItems Parameters, out Parser.TokenItem Result, out string ErrorMsg)
        {
            // initialize the outgoing variables
            ErrorMsg = "";
            Result = null;

            // make sure we have at least 1 parameter
            if (Parameters.Count != 1)
            {
                ErrorMsg = "Eval[] Operand Function requires 1 parameter.";
                return false;
            }

            // get the expression to be evaluated
            string expression = Support.DataTypeCheck.RemoveTextQuotes(Parameters[0].TokenName);

            // create the tokens
            Parser.Token tokens = new Parser.Token(expression);
            if (tokens.AnyErrors == true)
            {
                ErrorMsg = tokens.LastErrorMessage;
                return false;
            }

            // create the evaluator object
            Evaluator e = new Evaluator(tokens);

            string value = "";

            if (e.Evaluate(out value, out ErrorMsg) == false) return false;

            if (Support.DataTypeCheck.IsInteger(value) == true)
                Result = new Parser.TokenItem(value, Parser.TokenType.Token_Operand, Parser.TokenDataType.Token_DataType_Int, false);
            else if (Support.DataTypeCheck.IsDouble(value) == true)
                Result = new Parser.TokenItem(value, Parser.TokenType.Token_Operand, Parser.TokenDataType.Token_DataType_Double, false);
            else if (Support.DataTypeCheck.IsDate(value) == true)
                Result = new Parser.TokenItem(value, Parser.TokenType.Token_Operand, Parser.TokenDataType.Token_DataType_Date, false);
            else
                Result = new Parser.TokenItem(value, Parser.TokenType.Token_Operand, Parser.TokenDataType.Token_DataType_String, false);

            return true;
        }