Exemplo n.º 1
0
        public override Expression Clone()
        {
            var expression = new ExpressionFunction(Function);
            var nCount     = Parameter.Count;

            for (var nIndex = 0; nIndex < nCount; ++nIndex)
            {
                expression.Parameter.Add(Parameter[nIndex].Clone());
            }
            // foreach (BehaviourTreeExpression rExpression in Parameter)
            // {
            //     rBehaviourTreeExpression.Parameter.Add(rExpression.Clone());
            // }
            return(expression);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解析方法
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private bool Resolve_Function(out Expression e)
        {
            e = null;
            if (Current.Type != ExpressionToken.eType.Identifier)
            {
                return(false);
            }

            if (Peek.Value != "(")
            {
                return(false);
            }

            var rFunction = new ExpressionFunction(Current.Value);

            // 所有参数列表
            var rListToken     = new List <ExpressionToken>();
            var rListParameter = new List <ExpressionToken>();

            Read();

            var nCount = 0;

            while (true)
            {
                if (Current.Value == "(")
                {
                    nCount++;
                }
                else if (Current.Value == ")")
                {
                    nCount--;

                    if (0 == nCount)
                    {
                        Read();
                        break;
                    }
                }

                rListToken.Add(Current);

                Read();
            }

            // 移除开始与结束的括号
            rListToken.RemoveAt(0);
            rListToken.Add(new ExpressionToken(ExpressionToken.eType.End, null));

            foreach (var rToken in rListToken)
            {
                if (rToken.Value == "(")
                {
                    nCount++;
                }
                else if (rToken.Value == ")")
                {
                    nCount--;
                }
                if ((rToken.Value == "," && nCount == 0) || rToken.Type == ExpressionToken.eType.End)
                {
                    if (rListParameter.Count > 0)
                    {
                        var rResolve    = new ExpressionResolve(rListParameter.ToArray());
                        var rExpression = rResolve.Resolve();

                        // 添加到参数列表中
                        rFunction.Parameter.Add(rExpression);

                        rListParameter.Clear();
                    }
                }
                else
                {
                    rListParameter.Add(rToken);
                }
            }

            if (nCount != 0)
            {
                throw new Exception("方法( )不匹配");
            }
            e = rFunction;
            return(true);
        }