예제 #1
0
        /// <summary>
        ///    The logic of this method is obvious...
        ///    Evaluate the Left and Right Expression...
        ///    Query the Type of the expressions and perform
        ///    appropriate action
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont)
        {
            SYMBOL_INFO eval_left  = ex1.Evaluate(cont);
            SYMBOL_INFO eval_right = ex2.Evaluate(cont);

            SYMBOL_INFO ret_val = new SYMBOL_INFO();

            if (eval_left.Type == TYPE_INFO.TYPE_NUMERIC &&
                eval_right.Type == TYPE_INFO.TYPE_NUMERIC)
            {
                ret_val.Type       = TYPE_INFO.TYPE_BOOL;
                ret_val.SymbolName = "";

                if (m_op == RELATION_OPERATOR.TOK_EQ)
                {
                    ret_val.bol_val = eval_left.dbl_val == eval_right.dbl_val;
                }
                else if (m_op == RELATION_OPERATOR.TOK_NEQ)
                {
                    ret_val.bol_val = eval_left.dbl_val != eval_right.dbl_val;
                }
                else if (m_op == RELATION_OPERATOR.TOK_GT)
                {
                    ret_val.bol_val = eval_left.dbl_val > eval_right.dbl_val;
                }
                else if (m_op == RELATION_OPERATOR.TOK_GTE)
                {
                    ret_val.bol_val = eval_left.dbl_val >= eval_right.dbl_val;
                }
                else if (m_op == RELATION_OPERATOR.TOK_LTE)
                {
                    ret_val.bol_val = eval_left.dbl_val <= eval_right.dbl_val;
                }
                else if (m_op == RELATION_OPERATOR.TOK_LT)
                {
                    ret_val.bol_val = eval_left.dbl_val < eval_right.dbl_val;
                }


                return(ret_val);
            }
            else if (eval_left.Type == TYPE_INFO.TYPE_STRING &&
                     eval_right.Type == TYPE_INFO.TYPE_STRING)
            {
                ret_val.Type       = TYPE_INFO.TYPE_BOOL;
                ret_val.SymbolName = "";

                if (m_op == RELATION_OPERATOR.TOK_EQ)
                {
                    ret_val.bol_val = (String.Compare(
                                           eval_left.str_val,
                                           eval_right.str_val) == 0) ? true:false;
                }
                else if (m_op == RELATION_OPERATOR.TOK_NEQ)
                {
                    ret_val.bol_val = String.Compare(
                        eval_left.str_val,
                        eval_right.str_val) != 0;
                }
                else
                {
                    ret_val.bol_val = false;
                }


                return(ret_val);
            }
            if (eval_left.Type == TYPE_INFO.TYPE_BOOL &&
                eval_right.Type == TYPE_INFO.TYPE_BOOL)
            {
                ret_val.Type       = TYPE_INFO.TYPE_BOOL;
                ret_val.SymbolName = "";

                if (m_op == RELATION_OPERATOR.TOK_EQ)
                {
                    ret_val.bol_val = eval_left.bol_val == eval_right.bol_val;
                }
                else if (m_op == RELATION_OPERATOR.TOK_NEQ)
                {
                    ret_val.bol_val = eval_left.bol_val != eval_right.bol_val;
                }
                else
                {
                    ret_val.bol_val = false;
                }
                return(ret_val);
            }
            return(null);
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cont"></param>
 /// <returns></returns>
 public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont)
 {
     inf = (m_e1 == null) ? null : m_e1.Evaluate(cont);
     return(inf);
 }
예제 #3
0
 TYPE_INFO _type;       // Type
 /// <summary>
 ///     this Ctor just stores the variable name
 /// </summary>
 /// <param name="inf"></param>
 public Variable(SYMBOL_INFO inf)
 {
     m_name = inf.SymbolName;
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inf"></param>
 public VariableDeclStatement(SYMBOL_INFO inf)
 {
     m_inf = inf;
 }