示例#1
0
        //解析操作符
        private bool P_Operator(Stack <TempOperator> operateStack, Stack <CodeObject> objectStack)
        {
            TempOperator curr = TempOperator.GetOper(PeekToken().Type);

            if (curr == null)
            {
                return(false);
            }
            ReadToken();
            while (operateStack.Count > 0)
            {
                TempOperator oper = operateStack.Peek();
                if (oper.Level >= curr.Level)
                {
                    operateStack.Pop();
                    CodeOperator binexp = new CodeOperator(objectStack.Pop(), objectStack.Pop(), oper.Operator);
                    objectStack.Push(binexp);
                }
                else
                {
                    break;
                }
            }
            operateStack.Push(curr);
            return(true);
        }
示例#2
0
        //获取一个Object
        private CodeObject GetObject()
        {
            Stack <TempOperator> operateStack = new Stack <TempOperator>();
            Stack <CodeObject>   objectStack  = new Stack <CodeObject>();

            while (true)
            {
                objectStack.Push(GetOneObject());
                if (!P_Operator(operateStack, objectStack))
                {
                    break;
                }
            }
            while (true)
            {
                if (operateStack.Count <= 0)
                {
                    break;
                }
                TempOperator oper   = operateStack.Pop();
                CodeOperator binexp = new CodeOperator(objectStack.Pop(), objectStack.Pop(), oper.Operator);
                objectStack.Push(binexp);
            }
            CodeObject ret = objectStack.Pop();

            if (ret is CodeMember)
            {
                CodeMember member = ret as CodeMember;
                if (member.Calc == CALC.NONE)
                {
                    Token token = ReadToken();
                    switch (token.Type)
                    {
                    case TokenType.Assign:
                    case TokenType.AssignPlus:
                    case TokenType.AssignMinus:
                    case TokenType.AssignMultiply:
                    case TokenType.AssignDivide:
                    case TokenType.AssignModulo:
                    case TokenType.AssignCombine:
                    case TokenType.AssignInclusiveOr:
                    case TokenType.AssignXOR:
                    case TokenType.AssignShr:
                    case TokenType.AssignShi:
                        return(new CodeAssign(member, GetObject(), token.Type, m_strBreviary, token.SourceLine));

                    default:
                        UndoToken();
                        break;
                    }
                }
            }
            return(ret);
        }
示例#3
0
        private bool P_Operator(Stack <TempOperator> operateStack, Stack <CodeObject> objectStack)
        {
            TempOperator oper = TempOperator.GetOper(this.PeekToken().Type);

            if (oper == null)
            {
                return(false);
            }
            this.ReadToken();
            while (operateStack.Count > 0)
            {
                if (operateStack.Peek().Level < oper.Level)
                {
                    break;
                }
                objectStack.Push(new CodeOperator(objectStack.Pop(), objectStack.Pop(), operateStack.Pop().Operator, this.m_strBreviary, this.GetSourceLine()));
            }
            operateStack.Push(oper);
            return(true);
        }
示例#4
0
        //解析操作符
        private bool P_Operator(Stack <TempOperator> operateStack, Stack <CodeObject> objectStack)
        {
            TempOperator curr = TempOperator.GetOper(PeekToken().Type);

            if (curr == null)
            {
                return(false);
            }
            ReadToken();
            while (operateStack.Count > 0)
            {
                if (operateStack.Peek().Level >= curr.Level)
                {
                    objectStack.Push(new CodeOperator(objectStack.Pop(), objectStack.Pop(), operateStack.Pop().Operator, m_strBreviary, GetSourceLine()));
                }
                else
                {
                    break;
                }
            }
            operateStack.Push(curr);
            return(true);
        }