Inheritance: CodeObject
Exemplo n.º 1
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 (operateStack.Count > 0) {
                objectStack.Push(new CodeOperator(objectStack.Pop(), objectStack.Pop(), operateStack.Pop().Operator, m_strBreviary, GetSourceLine()));
            }
            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:
                            ret = new CodeAssign(member, GetObject(), token.Type, m_strBreviary, token.SourceLine);
                            break;
                        default:
                            UndoToken();
                            break;
                    }
                }
            }
			if (PeekToken ().Type == TokenType.QuestionMark) {
				ReadToken();
				CodeTernary ternary = new CodeTernary();
				ternary.Allow = ret;
				ternary.True = GetObject();
				ReadColon();
				ternary.False = GetObject();
				return ternary;
			}
            return ret;
        }
Exemplo n.º 2
0
 ScriptObject ParseAssign(CodeAssign assign)
 {
     if (assign.AssignType == TokenType.Assign) {
         var ret = ResolveOperand(assign.value);
         SetVariable(assign.member, ret);
         return ret;
     } else {
         return GetVariable(assign.member).AssignCompute(assign.AssignType, ResolveOperand(assign.value));
     }
 }
Exemplo n.º 3
0
 ScriptObject ParseAssign(CodeAssign assign)
 {
     if (assign.AssignType == TokenType.Assign) {
         var ret = ResolveOperand(assign.value);
         SetVariable(assign.member, ret);
         return ret;
     } else {
         ScriptObject obj = GetVariable(assign.member);
         ScriptString str = obj as ScriptString;
         if (str != null)
         {
             if (assign.AssignType == TokenType.AssignPlus)
                 return str.AssignPlus(ResolveOperand(assign.value));
             else
                 throw new ExecutionException(m_script, "string类型只支持[+=]赋值操作");
         }
         ScriptNumber num = obj as ScriptNumber;
         if (num != null)
         {
             ScriptNumber right = ResolveOperand(assign.value) as ScriptNumber;
             if (right == null)
                 throw new ExecutionException(m_script, "[+= -=...]值只能为 number类型");
             return num.AssignCompute(assign.AssignType, right);
         }
         throw new ExecutionException(m_script, "[+= -=...]左边值只能为number或者string");
     }
 }