Inheritance: CodeObject
 //获得单一变量
 private CodeObject GetOneObject()
 {
     CodeObject ret = null;
     Token token = ReadToken();
     bool not = false;
     bool negative = false;
     CALC calc = CALC.NONE;
     if (token.Type == TokenType.Not) {
         not = true;
         token = ReadToken();
     } else if (token.Type == TokenType.Minus) {
         negative = true;
         token = ReadToken();
     } else 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.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;
 }
 ScriptFunction ParseFunction(CodeFunction func)
 {
     return func.Func.Create().SetParentContext(this);
 }
示例#3
0
 ScriptFunction ParseFunction(CodeFunction func)
 {
     return ((ScriptFunction)func.Func.Clone()).SetParentVariable(GetContextVariables());
 }