Ejemplo n.º 1
0
        //执行函数校验
        private ExpressionToken VerifyFunction(ExpressionToken funtionToken, Stack <ExpressionToken> verifyStack)
        {
            if (!(verifyStack.Count == 0))
            {
                bool            doPop     = true;
                var             args      = new List <BaseMetadata>();
                ExpressionToken parameter = null;
                //弹出函数的参数,直到遇到"("时终止
                while (doPop && !(verifyStack.Count == 0))
                {
                    parameter = verifyStack.Pop();

                    if (ExpressionToken.ETokenType.ETOKEN_TYPE_CONSTANT == parameter.TokenType)
                    {
                        //常量
                        args.Add(parameter.Constant);
                    }
                    else if (ExpressionToken.ETokenType.ETOKEN_TYPE_VARIABLE == parameter.TokenType)
                    {
                        args.Add(parameter.Variable);
                    }
                    else if ("(".Equals(parameter.GetSplitor()))
                    {
                        doPop = false;
                    }
                    else
                    {
                        //没有找到应该存在的右括号
                        throw new IllegalExpressionException("表达式不合法,函数\"" + funtionToken.TokenText + "\"遇到非法参数" + parameter.ToString() + ";位置:" + parameter.StartPosition
                                                             , funtionToken.ToString()
                                                             , funtionToken.StartPosition);
                    }
                }

                if (doPop && (verifyStack.Count == 0))
                {
                    //操作栈以空,没有找到函数的左括号(
                    throw new IllegalExpressionException("表达式不合法,函数\"" + funtionToken.TokenText + "\"缺少\"(\";位置:" + (funtionToken.StartPosition + funtionToken.ToString().Length)
                                                         , funtionToken.ToString()
                                                         , funtionToken.StartPosition);
                }

                //校验函数
                var arguments = new BaseMetadata[args.Count];
                arguments = args.ToArray();
                Constant result = FunctionExecution.Verify(funtionToken.TokenText, funtionToken.StartPosition, arguments);
                return(ExpressionToken.CreateConstantToken(result));
            }
            else
            {
                //没有找到应该存在的右括号
                throw new IllegalExpressionException("表达式不合法,函数\"" + funtionToken.TokenText + "\"不完整"
                                                     , funtionToken.ToString()
                                                     , funtionToken.StartPosition);
            }
        }
Ejemplo n.º 2
0
 public Reference(ExpressionToken token, Constant[] args)
 {
     this.Token     = token;
     this.Arguments = args;
     //记录Reference实际的数据类型
     if (ExpressionToken.ETokenType.ETOKEN_TYPE_FUNCTION == token.TokenType)
     {
         Constant result = FunctionExecution.Verify(token.TokenText, token.StartPosition, args);
         dataType = result.GetDataType();
     }
     else if (ExpressionToken.ETokenType.ETOKEN_TYPE_OPERATOR == token.TokenType)
     {
         Operator op     = token.Op;
         Constant result = op.Verify(token.StartPosition, args);
         dataType = result.GetDataType();
     }
 }