Ejemplo n.º 1
0
        /// <summary>
        /// next statement
        /// </summary>
        /// <param name="s"></param>
        protected void doForEnd(Statement s)
        {
            if (m_forLoopStack.Count <= 0)
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_01);
            }

            ForRecord lr = m_forLoopStack.Peek();

            if (s.m_symbol != null && s.m_symbol != lr.LOOP_VAR_NAME)
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_01);
            }

            if (lr.UpdateLoop())
            {
                m_forLoopStack.Pop();
            }
            else
            {
                // set the next index to the for begin line
                m_index = lr.LOOP_BEGIN_INDEX;
                while (m_statements[m_index].m_type != Statement.TYPE_FOR_BEGIN)
                {
                    m_index++;
                }

                m_index++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// for statement
        /// </summary>
        /// <param name="s"></param>
        protected void doForBegin(Statement s)
        {
            string    varName = s.m_symbol;
            VarSymbol symbol  = m_symbolTable.ResolveVar(varName);

            ForRecord lr = null;

            // use the top of LoopRecord or push a new one ?
            if (m_forLoopStack.Count > 0)
            {
                lr = m_forLoopStack.Peek();
            }

            if (lr == null || lr.LOOP_VAR_NAME != varName)
            {
                lr = new ForRecord();
                m_forLoopStack.Push(lr);
            }

            BaseData startValue = calculateExp(s.m_expressList[0]).m_value;
            BaseData endValue   = calculateExp(s.m_expressList[1]).m_value;
            BaseData stepValue  = calculateExp(s.m_expressList[2]).m_value;

            // check the value type
            if (startValue.TYPE != BaseData.TYPE_INT && startValue.TYPE != BaseData.TYPE_FLOAT)
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_02);
            }
            if (endValue.TYPE != BaseData.TYPE_INT && endValue.TYPE != BaseData.TYPE_FLOAT)
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_02);
            }
            if (stepValue.TYPE != BaseData.TYPE_INT && stepValue.TYPE != BaseData.TYPE_FLOAT)
            {
                throw new ErrorCode(ErrorCode.ERROR_CODE_02);
            }

            // initital the loop var
            lr.SetLoopRecord(symbol, endValue, stepValue);
            lr.SetBeginIndex(s.m_lineIndex);

            // init the symbol value
            symbol.VALUE = startValue;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// for statement 
        /// </summary>
        /// <param name="s"></param>
        protected void doForBegin( Statement s )
        {
            string varName = s.m_symbol;
            VarSymbol symbol = m_symbolTable.ResolveVar(varName);

            ForRecord lr = null;

            // use the top of LoopRecord or push a new one ? 
            if( m_forLoopStack.Count > 0 )
                lr = m_forLoopStack.Peek();

            if( lr == null || lr.LOOP_VAR_NAME != varName )
            {
                lr = new ForRecord();
                m_forLoopStack.Push(lr);
            }

            BaseData startValue = calculateExp(s.m_expressList[0]).m_value;
            BaseData endValue = calculateExp(s.m_expressList[1]).m_value;
            BaseData stepValue = calculateExp(s.m_expressList[2]).m_value;

            // check the value type 
            if (startValue.TYPE != BaseData.TYPE_INT && startValue.TYPE != BaseData.TYPE_FLOAT)
                throw new ErrorCode(ErrorCode.ERROR_CODE_02);
            if (endValue.TYPE != BaseData.TYPE_INT && endValue.TYPE != BaseData.TYPE_FLOAT)
                throw new ErrorCode(ErrorCode.ERROR_CODE_02);
            if (stepValue.TYPE != BaseData.TYPE_INT && stepValue.TYPE != BaseData.TYPE_FLOAT)
                throw new ErrorCode(ErrorCode.ERROR_CODE_02);

            // initital the loop var 
            lr.SetLoopRecord(symbol, endValue, stepValue);
            lr.SetBeginIndex(s.m_lineIndex);

            // init the symbol value 
            symbol.VALUE = startValue;
        }