Exemplo n.º 1
0
        /// <summary>
        /// plus
        /// </summary>
        /// <param name="lhs"></param>
        /// <param name="rhs"></param>
        /// <returns></returns>
        public static BaseData operator +(BaseData lhs, BaseData rhs)
        {
            BaseData result = lhs;

            if (lhs.m_type == BaseData.TYPE_STRING || rhs.m_type == BaseData.TYPE_STRING)
            {
                result.Convert(BaseData.TYPE_STRING);
                lhs.Convert(BaseData.TYPE_STRING);
                rhs.Convert(BaseData.TYPE_STRING);

                result.m_stringVal = lhs.m_stringVal + rhs.m_stringVal;
            }
            else if (lhs.m_type == BaseData.TYPE_FLOAT || rhs.m_type == BaseData.TYPE_FLOAT)
            {
                result.Convert(BaseData.TYPE_FLOAT);
                lhs.Convert(BaseData.TYPE_FLOAT);
                rhs.Convert(BaseData.TYPE_FLOAT);

                result.m_floatVal = lhs.m_floatVal + rhs.m_floatVal;
            }
            else if (lhs.m_type == BaseData.TYPE_INT && rhs.m_type == BaseData.TYPE_INT)
            {
                result.m_intVal = lhs.m_intVal + rhs.m_intVal;
            }
            else
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_12);
            }

            return(result);
        }
Exemplo n.º 2
0
        protected void onInput(Statement s)
        {
            List <Expression> varList = s.m_expressList;
            string            input   = null;

            foreach (Expression exp in varList)
            {
                input = m_apiCall.Input();
                BaseData dat = BaseData.Parser(input);

                // 转换为字符串
                if (exp.m_symbolName.EndsWith("$"))
                {
                    dat.Convert(BaseData.TYPE_STRING);
                }

                if (exp.m_type == Expression.EXP_SYMBOL)
                {
                    VarSymbol symbol = m_symbolTable.ResolveVar(exp.m_symbolName);
                    symbol.VALUE = dat;
                }
                else if (exp.m_type == Expression.EXP_ARRAY_SYMBOL)
                {
                    List <int>  indexs    = expressListToIndexs(exp.m_funcParams);
                    ArraySymbol arrSymbol = m_symbolTable.ResolveArray(exp.m_symbolName, indexs);
                    arrSymbol.SetValue(indexs, dat);
                }
                else
                {
                    throw new ErrorCode(ErrorCode.ERROR_CODE_02);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// expression list to indexs
        /// </summary>
        /// <param name="expList"></param>
        /// <returns></returns>
        protected List <int> expressListToIndexs(List <Expression> expList)
        {
            List <int> indexs = new List <int>();

            foreach (Expression exp in expList)
            {
                BaseData bd = calculateExp(exp).m_value;
                bd.Convert(BaseData.TYPE_INT);

                indexs.Add(bd.INT_VAL);
            }

            return(indexs);
        }
Exemplo n.º 4
0
        /// <summary>
        /// set value
        /// </summary>
        /// <param name="indexs"></param>
        /// <param name="val"></param>
        public void SetValue(List <int> indexs, BaseData val)
        {
            if (indexs.Count != m_dimension.Count)
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_08);
            }

            val.Convert(m_dataType);

            int index = 0;

            int factor = 1;

            for (int i = m_dimension.Count - 1; i >= 0; i--)
            {
                index  += factor * indexs[i];
                factor *= m_dimension[i];
            }

            m_data[index] = val;
        }
Exemplo n.º 5
0
        protected void onOnGoto(Statement s)
        {
            BaseData val = calculateExp(s.m_expressList[0]).m_value;

            val.Convert(BaseData.TYPE_INT);
            int index = val.INT_VAL;

            if (index <= 0 || index > s.m_dataList.Count)
            {
                return;
            }

            val = s.m_dataList[index - 1];

            if (m_lineNumDic.ContainsKey(val.INT_VAL))
            {
                m_index = m_lineNumDic[val.INT_VAL];
            }
            else
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_07);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// set value 
        /// </summary>
        /// <param name="indexs"></param>
        /// <param name="val"></param>
        public void SetValue( List<int> indexs, BaseData val )
        {
            if (indexs.Count != m_dimension.Count)
                throw new ErrorCode(ErrorCode.ERROR_CODE_08);

            val.Convert(m_dataType);

            int index = 0;

            int factor = 1;
            for (int i = m_dimension.Count - 1; i >= 0; i-- )
            {
                index += factor * indexs[i];
                factor *= m_dimension[i];
            }

            m_data[index] = val;
        }