Esempio n. 1
0
 ScriptObject ParseScriptObject(CodeScriptObject obj)
 {
     //此处原先使用Clone 是因为 number 和 string 有自运算的操作 会影响常量 但是现在设置变量会调用Assign() 基础类型会自动复制一次 所以去掉clone
     return(obj.Object);
     //return obj.Object.Clone();
 }
Esempio n. 2
0
 ScriptObject ParseScriptObject(CodeScriptObject obj)
 {
     return(obj.Object);
 }
Esempio n. 3
0
        //获得单一变量
        private CodeObject GetOneObject()
        {
            CodeObject ret      = null;
            Token      token    = ReadToken();
            bool       not      = false;
            bool       minus    = false;
            bool       negative = false;
            CALC       calc     = CALC.NONE;

            while (true)
            {
                if (token.Type == TokenType.Not)
                {
                    not = true;
                }
                else if (token.Type == TokenType.Minus)
                {
                    minus = true;
                }
                else if (token.Type == TokenType.Negative)
                {
                    negative = true;
                }
                else
                {
                    break;
                }
                token = ReadToken();
            }
            if (token.Type == TokenType.Increment)
            {
                calc  = CALC.PRE_INCREMENT;
                token = ReadToken();
            }
            else if (token.Type == TokenType.Decrement)
            {
                calc  = CALC.PRE_DECREMENT;
                token = ReadToken();
            }
            switch (token.Type)
            {
            case TokenType.Identifier:
                ret = new CodeMember((string)token.Lexeme);
                break;

            case TokenType.Function:
                UndoToken();
                ret = new CodeFunction(ParseFunctionDeclaration(false));
                break;

            case TokenType.LeftPar:
                ret = new CodeRegion(GetObject());
                ReadRightParenthesis();
                break;

            case TokenType.LeftBracket:
                UndoToken();
                ret = GetArray();
                break;

            case TokenType.LeftBrace:
                UndoToken();
                ret = GetTable();
                break;

            case TokenType.Eval:
                ret = GetEval();
                break;

            case TokenType.Null:
                ret = new CodeScriptObject(m_script, null);
                break;

            case TokenType.Boolean:
            case TokenType.Number:
            case TokenType.String:
            case TokenType.SimpleString:
                ret = new CodeScriptObject(m_script, token.Lexeme);
                break;

            default:
                throw new ParserException("Object起始关键字错误 ", token);
            }
            ret.StackInfo = new StackInfo(m_strBreviary, token.SourceLine);
            ret           = GetVariable(ret);
            ret.Not       = not;
            ret.Minus     = minus;
            ret.Negative  = negative;
            if (ret is CodeMember)
            {
                if (calc != CALC.NONE)
                {
                    ((CodeMember)ret).Calc = calc;
                }
                else
                {
                    Token peek = ReadToken();
                    if (peek.Type == TokenType.Increment)
                    {
                        calc = CALC.POST_INCREMENT;
                    }
                    else if (peek.Type == TokenType.Decrement)
                    {
                        calc = CALC.POST_DECREMENT;
                    }
                    else
                    {
                        UndoToken();
                    }
                    if (calc != CALC.NONE)
                    {
                        ((CodeMember)ret).Calc = calc;
                    }
                }
            }
            else if (calc != CALC.NONE)
            {
                throw new ParserException("++ 或者 -- 只支持变量的操作", token);
            }
            return(ret);
        }
Esempio n. 4
0
        private CodeObject GetOneObject()
        {
            CodeObject parent = null;
            Token      token  = this.ReadToken();
            bool       flag   = false;
            bool       flag2  = false;
            bool       flag3  = false;
            CALC       nONE   = CALC.NONE;

            while (true)
            {
                if (token.Type == Scorpio.Compiler.TokenType.Not)
                {
                    flag = true;
                }
                else if (token.Type == Scorpio.Compiler.TokenType.Minus)
                {
                    flag2 = true;
                }
                else
                {
                    if (token.Type != Scorpio.Compiler.TokenType.Negative)
                    {
                        break;
                    }
                    flag3 = true;
                }
                token = this.ReadToken();
            }
            if (token.Type == Scorpio.Compiler.TokenType.Increment)
            {
                nONE  = CALC.PRE_INCREMENT;
                token = this.ReadToken();
            }
            else if (token.Type == Scorpio.Compiler.TokenType.Decrement)
            {
                nONE  = CALC.PRE_DECREMENT;
                token = this.ReadToken();
            }
            switch (token.Type)
            {
            case Scorpio.Compiler.TokenType.LeftBrace:
                this.UndoToken();
                parent = this.GetTable();
                break;

            case Scorpio.Compiler.TokenType.LeftPar:
                parent = new CodeRegion(this.GetObject());
                this.ReadRightParenthesis();
                break;

            case Scorpio.Compiler.TokenType.LeftBracket:
                this.UndoToken();
                parent = this.GetArray();
                break;

            case Scorpio.Compiler.TokenType.Function:
                this.UndoToken();
                parent = new CodeFunction(this.ParseFunctionDeclaration(false));
                break;

            case Scorpio.Compiler.TokenType.Boolean:
            case Scorpio.Compiler.TokenType.Number:
            case Scorpio.Compiler.TokenType.String:
            case Scorpio.Compiler.TokenType.SimpleString:
                parent = new CodeScriptObject(this.m_script, token.Lexeme);
                break;

            case Scorpio.Compiler.TokenType.Null:
                parent = new CodeScriptObject(this.m_script, null);
                break;

            case Scorpio.Compiler.TokenType.Eval:
                parent = this.GetEval();
                break;

            case Scorpio.Compiler.TokenType.Identifier:
                parent = new CodeMember((string)token.Lexeme);
                break;

            default:
                throw new ParserException("Object起始关键字错误 ", token);
            }
            parent.StackInfo = new StackInfo(this.m_strBreviary, token.SourceLine);
            parent           = this.GetVariable(parent);
            parent.Not       = flag;
            parent.Minus     = flag2;
            parent.Negative  = flag3;
            if (parent is CodeMember)
            {
                if (nONE != CALC.NONE)
                {
                    ((CodeMember)parent).Calc = nONE;
                    return(parent);
                }
                Token token2 = this.ReadToken();
                if (token2.Type == Scorpio.Compiler.TokenType.Increment)
                {
                    nONE = CALC.POST_INCREMENT;
                }
                else if (token2.Type == Scorpio.Compiler.TokenType.Decrement)
                {
                    nONE = CALC.POST_DECREMENT;
                }
                else
                {
                    this.UndoToken();
                }
                if (nONE != CALC.NONE)
                {
                    ((CodeMember)parent).Calc = nONE;
                }
                return(parent);
            }
            if (nONE != CALC.NONE)
            {
                throw new ParserException("++ 或者 -- 只支持变量的操作", token);
            }
            return(parent);
        }
Esempio n. 5
0
 ScriptObject ParseScriptObject(CodeScriptObject obj)
 {
     return(obj.Object.Clone());
 }