コード例 #1
0
        /// <summary>
        /// 处理乘除运算
        /// </summary>
        /// <returns></returns>
        private ExpTreeNode DoMulDiv(ParsingContext context)
        {
            ExpTreeNode node1 = DoSgOP(context);

            char ch = context.CurrentChar;

            while (ch == '*' || ch == '/')
            {
                Operation_IDs oID = Operation_IDs.OI_NONE;

                oID = (ch == '*') ? Operation_IDs.OI_MUL : Operation_IDs.OI_DIV;

                OutputID(context, oID, ch.ToString(), context.Position);

                int nPos = context.Position;

                context.Position++;
                ExpTreeNode node2 = DoSgOP(context);

                node1 = NewTreeNode(context, node1, node2, oID, nPos);

                ch = context.CurrentChar;
            }

            return(node1);
        }
コード例 #2
0
ファイル: ExpClasses.cs プロジェクト: ounata/AK47-2016Source
 internal ParseIdentifier(Operation_IDs oID, string strID, int nPos, ParseIdentifier prev)
 {
     this.operationID    = oID;
     this.identifier     = strID;
     this.position       = nPos;
     this.prevIdentifier = prev;
 }
コード例 #3
0
        //私有方法

        /// <summary>
        /// 顺序输出标识符
        /// </summary>
        /// <param name="oID"></param>
        /// <param name="strID"></param>
        /// <param name="nPos"></param>
        private void OutputID(Operation_IDs oID, string strID, int nPos)
        {
            if (OutputIdentifiers)
            {
                ParseIdentifier pi = new ParseIdentifier(oID, strID, nPos, _CurrentIdentifier);

                if (_CurrentIdentifier == null)
                {
                    if (_ParentIdentifier == null)
                    {
                        _Identifiers = pi;
                    }
                    else
                    {
                        _ParentIdentifier._SubIdentifier = pi;
                    }
                }
                else
                {
                    _CurrentIdentifier._NextIdentifier = pi;
                }

                pi._ParentIdentifier = _ParentIdentifier;
                _CurrentIdentifier   = pi;
            }
        }
コード例 #4
0
        private static void OutputID(ParsingContext context, Operation_IDs oID, string strID, int nPos)
        {
            if (context.OutputIdentifiers)
            {
                ParseIdentifier pi = new ParseIdentifier(oID, strID, nPos, context.CurrentIdentifier);

                if (context.CurrentIdentifier == null)
                {
                    if (context.ParentIdentifier == null)
                    {
                        context.Identifiers = pi;
                    }
                    else
                    {
                        context.ParentIdentifier.SubIdentifier = pi;
                    }
                }
                else
                {
                    context.CurrentIdentifier.NextIdentifier = pi;
                }

                pi.ParentIdentifier       = context.ParentIdentifier;
                context.CurrentIdentifier = pi;
            }
        }
コード例 #5
0
        private EXP_TreeNode DoLogical_AND_OR(char chSensitive, Operation_IDs oID, DoNextOP nextOP)
        {
            EXP_TreeNode node  = null;
            EXP_TreeNode node1 = nextOP();
            EXP_TreeNode node2 = null;

            while (_ExpressionChars[_Position] == chSensitive)
            {
                int  nPos = _Position;
                char op   = _ExpressionChars[_Position++];

                if (op == chSensitive)
                {
                    OutputID(oID, chSensitive.ToString() + chSensitive.ToString(), nPos);
                    _Position++;
                }

                node2 = nextOP();

                node = NewTreeNode(node1, node2, oID, nPos);

                node1 = node;
            }

            return(node1);
        }
コード例 #6
0
 public ParseIdentifier(Operation_IDs oID, string strID, int nPos, ParseIdentifier prev)
 {
     _OperationID    = oID;
     _Identifier     = strID;
     _Position       = nPos;
     _PrevIdentifier = prev;
 }
コード例 #7
0
        /// <summary>
        /// 处理乘除运算
        /// </summary>
        /// <returns></returns>
        private EXP_TreeNode DoMulDiv()
        {
            EXP_TreeNode node  = null;
            EXP_TreeNode node1 = DoSgOP();
            EXP_TreeNode node2 = null;

            char ch = _ExpressionChars[_Position];

            while (ch == '*' || ch == '/')
            {
                Operation_IDs oID = Operation_IDs.OI_NONE;

                oID = (ch == '*') ? Operation_IDs.OI_MUL : Operation_IDs.OI_DIV;

                OutputID(oID, ch.ToString(), _Position);

                int nPos = _Position;

                _Position++;
                node2 = DoSgOP();

                node  = NewTreeNode(node1, node2, oID, nPos);
                node1 = node;

                ch = _ExpressionChars[_Position];
            }

            return(node1);
        }
コード例 #8
0
        /// <summary>
        /// 处理加减运算
        /// </summary>
        /// <returns></returns>
        private ExpTreeNode DoAddSub(ParsingContext context)
        {
            ExpTreeNode node  = null;
            ExpTreeNode node1 = DoMulDiv(context);
            ExpTreeNode node2 = null;

            char ch = context.CurrentChar;

            while (ch == '-' || ch == '+')
            {
                Operation_IDs oID = Operation_IDs.OI_NONE;

                oID = (ch == '-') ? Operation_IDs.OI_MINUS : Operation_IDs.OI_ADD;

                OutputID(context, oID, ch.ToString(), context.Position);

                int nPos = context.Position;

                context.Position++;

                node2 = DoMulDiv(context);

                node = NewTreeNode(context, node1, node2, oID, nPos);

                node1 = node;

                ch = context.CurrentChar;
            }

            return(node1);
        }
コード例 #9
0
        private EXP_TreeNode NewTreeNode(EXP_TreeNode left, EXP_TreeNode right, Operation_IDs oID, int nPosition)
        {
            EXP_TreeNode node = NewTreeNode(left, right, oID);

            node._Position = nPosition;

            return(node);
        }
コード例 #10
0
        /// <summary>
        /// 生成一个新的二叉树节点
        /// </summary>
        /// <param name="left">左子树</param>
        /// <param name="right">右子树</param>
        /// <param name="oID">操作类型</param>
        /// <returns></returns>
        private EXP_TreeNode NewTreeNode(EXP_TreeNode left, EXP_TreeNode right, Operation_IDs oID)
        {
            EXP_TreeNode node = NewTreeNode();

            node._Left        = left;
            node._Right       = right;
            node._OperationID = oID;

            return(node);
        }
コード例 #11
0
ファイル: ExpClasses.cs プロジェクト: ounata/AK47-2016Source
        /// <summary>
        /// 重载实现二叉树的反序列化
        /// </summary>
        /// <param name="info">The object to be populated with serialization information.</param>
        /// <param name="context">The destination context of the serialization.</param>
        /// <remarks>
        /// 二叉树的反序列化
        /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Test\Expression\ExpressionParserTest.cs" region="Serialization" lang="cs" />
        /// </remarks>
        private ExpTreeNode(SerializationInfo info, StreamingContext context)
        {
            this.left        = (ExpTreeNode)info.GetValue("Left", typeof(ExpTreeNode));
            this.right       = (ExpTreeNode)info.GetValue("Right", typeof(ExpTreeNode));
            this.position    = info.GetInt32("Position");
            this.operationID = (Operation_IDs)info.GetInt16("OperationID");

            string valueTypeName = info.GetString("ValueType");

            if (valueTypeName != "NullValue")
            {
                this.nodeValue = (Object)info.GetValue("Value", Type.GetType(valueTypeName));
            }
            else
            {
                this.nodeValue = (Object)info.GetValue("Value", typeof(Object));
            }
            this.functionParams = (List <ExpTreeNode>)info.GetValue("Params", typeof(ExpTreeNode));
            this.functionName   = info.GetString("FunctionName");
        }
コード例 #12
0
        private EXP_TreeNode DoFunction(string strID)
        {
            Operation_IDs oID = Operation_IDs.OI_USERDEFINE;

            EXP_TreeNode node = null;

            string strLower = strID.ToLower();

            if (strLower == "true" || strLower == "false")
            {
                node              = NewTreeNode();
                node._Position    = _Position - strID.Length;
                node._OperationID = Operation_IDs.OI_BOOLEAN;
                node._Value       = bool.Parse(strLower);

                OutputID(Operation_IDs.OI_BOOLEAN, strID, node._Position);
            }
            else
            {
                node = GetFunctionNode(oID, strID);
            }

            return(node);
        }
コード例 #13
0
        private ExpTreeNode GetFunctionNode(ParsingContext context, Operation_IDs funcID, string strID)
        {
            ExpTreeNode node = null;
            ExpTreeNode nodeTemp = null;
            List<ExpTreeNode> paramBase = new List<ExpTreeNode>(4);

            int nStartFunction = context.Position - strID.Length;

            OutputID(context, Operation_IDs.OI_USERDEFINE, strID, nStartFunction);

            if (context.CurrentChar == '(')	//有参数
            {
                OutputIDToSubLevel(context);
                OutputID(context, Operation_IDs.OI_LBRACKET, "(", context.Position);

                do
                {
                    context.Position++;
                    SkipSpaces(context);

                    nodeTemp = DoExpression(context);

                    if (nodeTemp != null)
                    {
                        paramBase.Add(nodeTemp);

                        SkipSpaces(context);
                    }
                    else
                        break;

                    if (context.CurrentChar == ',')
                        OutputID(context, Operation_IDs.OI_COMMA, ",", context.Position);
                }
                while (context.CurrentChar == ',');

                if (context.CurrentChar == ')')
                {
                    OutputID(context, Operation_IDs.OI_RBRACKET, ")", context.Position);
                    OutputIDToParentLevel(context);

                    context.Position++;
                    node = NewTreeNode(context);
                    node.Position = nStartFunction;
                    node.Params = paramBase;
                    node.OperationID = funcID;

                    if (funcID == Operation_IDs.OI_USERDEFINE)
                        node.FunctionName = strID;
                }
                else
                    throw ParsingException.NewParsingException(ParseError.peCharExpected, context.Position, ")");

                SkipSpaces(context);
            }
            else	//没有参数
            {
                node = NewTreeNode(context);
                node.Position = nStartFunction;
                node.Params = paramBase;
                node.OperationID = funcID;

                if (funcID == Operation_IDs.OI_USERDEFINE)
                    node.FunctionName = strID;
            }

            return node;
        }
コード例 #14
0
        /// <summary>
        /// 逻辑比较运算
        /// </summary>
        /// <returns></returns>
        private EXP_TreeNode DoLogicalOP()
        {
            EXP_TreeNode node  = null;
            EXP_TreeNode node1 = DoAddSub();
            EXP_TreeNode node2 = null;

            char op = _ExpressionChars[_Position];

            string strID = "";

            while (op == '>' || op == '<' || op == '=')
            {
                int nPos = _Position;

                Operation_IDs oID = Operation_IDs.OI_NONE;

                if (_ExpressionChars[++_Position] == '=')
                {
                    switch (op)
                    {
                    case '>':                                   //>=
                        oID   = Operation_IDs.OI_GREATEQUAL;
                        strID = ">=";
                        break;

                    case '<':                                   //<=
                        oID   = Operation_IDs.OI_LESSEQUAL;
                        strID = "<=";
                        break;

                    case '=':                                   //==
                        oID   = Operation_IDs.OI_EQUAL;
                        strID = "==";
                        break;

                    default: throw ParsingException.NewParsingException(Parse_Error.peInvalidOperator,
                                                                        _Position, op.ToString());
                    }

                    _Position++;
                }
                else
                {
                    if (_ExpressionChars[_Position] == '>')
                    {
                        if (op == '<')                          //<>
                        {
                            strID = "<>";
                            oID   = Operation_IDs.OI_NOT_EQUAL;
                            _Position++;
                        }
                        else
                        {
                            throw ParsingException.NewParsingException(Parse_Error.peInvalidOperator,
                                                                       _Position, op.ToString());
                        }
                    }
                    else
                    {
                        switch (op)
                        {
                        case '>':
                            oID   = Operation_IDs.OI_GREAT;
                            strID = ">";
                            break;

                        case '<':
                            oID   = Operation_IDs.OI_LESS;
                            strID = "<";
                            break;

                        default:
                            throw ParsingException.NewParsingException(Parse_Error.peInvalidOperator,
                                                                       _Position, op.ToString());
                        }
                    }
                }

                OutputID(oID, strID, nPos);

                node2 = DoAddSub();

                node = NewTreeNode(node1, node2, oID, nPos);

                node1 = node;

                op = _ExpressionChars[_Position];
            }

            return(node1);
        }
コード例 #15
0
        private static ExpTreeNode NewTreeNode(ParsingContext context, ExpTreeNode left, ExpTreeNode right, Operation_IDs oID, int nPosition)
        {
            ExpTreeNode node = NewTreeNode(context, left, right, oID);

            node.Position = nPosition;

            return node;
        }
コード例 #16
0
		private EXP_TreeNode DoLogical_AND_OR(char chSensitive, Operation_IDs oID, DoNextOP nextOP)
		{
			EXP_TreeNode node = null;
			EXP_TreeNode node1 = nextOP();
			EXP_TreeNode node2 = null;

			while (_ExpressionChars[_Position] == chSensitive)
			{
				int nPos = _Position;
				char op = _ExpressionChars[_Position++];

				if (op == chSensitive)
				{
					OutputID(oID, chSensitive.ToString() + chSensitive.ToString(), nPos);
					_Position++;
				}

				node2 = nextOP();

				node = NewTreeNode(node1, node2, oID, nPos);

				node1 = node;
			}

			return node1;
		}
コード例 #17
0
		//私有方法

		/// <summary>
		/// 顺序输出标识符
		/// </summary>
		/// <param name="oID"></param>
		/// <param name="strID"></param>
		/// <param name="nPos"></param>
		private void OutputID(Operation_IDs oID, string strID, int nPos)
		{
			if (OutputIdentifiers)
			{
				ParseIdentifier pi = new ParseIdentifier(oID, strID, nPos, _CurrentIdentifier);

				if (_CurrentIdentifier == null)
				{
					if (_ParentIdentifier == null)
						_Identifiers = pi;
					else
						_ParentIdentifier._SubIdentifier = pi;
				}
				else
					_CurrentIdentifier._NextIdentifier = pi;

				pi._ParentIdentifier = _ParentIdentifier;
				_CurrentIdentifier = pi;
			}
		}
コード例 #18
0
		/// <summary>
		/// 生成一个新的二叉树节点
		/// </summary>
		/// <param name="left">左子树</param>
		/// <param name="right">右子树</param>
		/// <param name="oID">操作类型</param>
		/// <returns></returns>
		private EXP_TreeNode NewTreeNode(EXP_TreeNode left, EXP_TreeNode right, Operation_IDs oID)
		{
			EXP_TreeNode node = NewTreeNode();

			node._Left = left;
			node._Right = right;
			node._OperationID = oID;

			return node;
		}
コード例 #19
0
		EXP_TreeNode GetFunctionNode(Operation_IDs funcID, string strID)
		{
			EXP_TreeNode node = null;
			EXP_TreeNode nodeTemp = null;
			ArrayList paramBase = null;

			int nStartFunction = _Position - strID.Length;

			OutputID(Operation_IDs.OI_USERDEFINE, strID, nStartFunction);

			if (_ExpressionChars[_Position] == '(')	//有参数
			{
				OutputIDToSubLevel();
				OutputID(Operation_IDs.OI_LBRACKET, "(", _Position);

				do
				{
					_Position++;
					SkipSpaces();

					nodeTemp = DoExpression();

					if (nodeTemp != null)
					{
						if (paramBase == null)
							paramBase = new ArrayList(4);

						paramBase.Add(nodeTemp);

						SkipSpaces();
					}
					else
						break;

					if (_ExpressionChars[_Position] == ',')
						OutputID(Operation_IDs.OI_COMMA, ",", _Position);
				}
				while (_ExpressionChars[_Position] == ',');

				if (_ExpressionChars[_Position] == ')')
				{
					OutputID(Operation_IDs.OI_RBRACKET, ")", _Position);
					OutputIDToParentLevel();

					_Position++;
					node = NewTreeNode();
					node._Position = nStartFunction;
					node._Params = paramBase;
					node._OperationID = funcID;

					if (funcID == Operation_IDs.OI_USERDEFINE)
						node._FunctionName = strID;
				}
				else
					throw ParsingException.NewParsingException(Parse_Error.peCharExpected, _Position, ")");

				SkipSpaces();
			}
			else	//没有参数
			{
				node = NewTreeNode();
				node._Position = nStartFunction;
				node._Params = paramBase;
				node._OperationID = funcID;

				if (funcID == Operation_IDs.OI_USERDEFINE)
					node._FunctionName = strID;
			}

			return node;
		}
コード例 #20
0
        /// <summary>
        /// 生成一个新的二叉树节点
        /// </summary>
        /// <param name="context">运行上下文</param>
        /// <param name="left">左子树</param>
        /// <param name="right">右子树</param>
        /// <param name="oID">操作类型</param>
        /// <returns></returns>
        private static ExpTreeNode NewTreeNode(ParsingContext context, ExpTreeNode left, ExpTreeNode right, Operation_IDs oID)
        {
            ExpTreeNode node = NewTreeNode(context);

            node.Left        = left;
            node.Right       = right;
            node.OperationID = oID;

            return(node);
        }
コード例 #21
0
        private static ExpTreeNode NewTreeNode(ParsingContext context, ExpTreeNode left, ExpTreeNode right, Operation_IDs oID, int nPosition)
        {
            ExpTreeNode node = NewTreeNode(context, left, right, oID);

            node.Position = nPosition;

            return(node);
        }
コード例 #22
0
		private EXP_TreeNode NewTreeNode(EXP_TreeNode left, EXP_TreeNode right, Operation_IDs oID, int nPosition)
		{
			EXP_TreeNode node = NewTreeNode(left, right, oID);

			node._Position = nPosition;

			return node;
		}
コード例 #23
0
        /// <summary>
        /// 生成一个新的二叉树节点
        /// </summary>
        /// <param name="context">运行上下文</param>
        /// <param name="left">左子树</param>
        /// <param name="right">右子树</param>
        /// <param name="oID">操作类型</param>
        /// <returns></returns>
        private static ExpTreeNode NewTreeNode(ParsingContext context, ExpTreeNode left, ExpTreeNode right, Operation_IDs oID)
        {
            ExpTreeNode node = NewTreeNode(context);

            node.Left = left;
            node.Right = right;
            node.OperationID = oID;

            return node;
        }
コード例 #24
0
        EXP_TreeNode GetFunctionNode(Operation_IDs funcID, string strID)
        {
            EXP_TreeNode node      = null;
            EXP_TreeNode nodeTemp  = null;
            ArrayList    paramBase = new ArrayList(4);

            int nStartFunction = _Position - strID.Length;

            OutputID(Operation_IDs.OI_USERDEFINE, strID, nStartFunction);

            if (_ExpressionChars[_Position] == '(')             //有参数
            {
                OutputIDToSubLevel();
                OutputID(Operation_IDs.OI_LBRACKET, "(", _Position);

                do
                {
                    _Position++;
                    SkipSpaces();

                    nodeTemp = DoExpression();

                    if (nodeTemp != null)
                    {
                        paramBase.Add(nodeTemp);

                        SkipSpaces();
                    }
                    else
                    {
                        break;
                    }

                    if (_ExpressionChars[_Position] == ',')
                    {
                        OutputID(Operation_IDs.OI_COMMA, ",", _Position);
                    }
                }while(_ExpressionChars[_Position] == ',');

                if (_ExpressionChars[_Position] == ')')
                {
                    OutputID(Operation_IDs.OI_RBRACKET, ")", _Position);
                    OutputIDToParentLevel();

                    _Position++;
                    node              = NewTreeNode();
                    node._Position    = nStartFunction;
                    node._Params      = paramBase;
                    node._OperationID = funcID;

                    if (funcID == Operation_IDs.OI_USERDEFINE)
                    {
                        node._FunctionName = strID;
                    }
                }
                else
                {
                    throw ParsingException.NewParsingException(Parse_Error.peCharExpected, _Position, ")");
                }

                SkipSpaces();
            }
            else                //没有参数
            {
                node              = NewTreeNode();
                node._Position    = nStartFunction;
                node._Params      = paramBase;
                node._OperationID = funcID;

                if (funcID == Operation_IDs.OI_USERDEFINE)
                {
                    node._FunctionName = strID;
                }
            }

            return(node);
        }
コード例 #25
0
        private static ExpTreeNode DoLogical_AND_OR(ParsingContext context, char chSensitive, Operation_IDs oID, Func <ParsingContext, ExpTreeNode> doNextOP)
        {
            ExpTreeNode node  = null;
            ExpTreeNode node1 = doNextOP(context);
            ExpTreeNode node2 = null;

            while (context.CurrentChar == chSensitive)
            {
                int  nPos = context.Position;
                char op   = context.ExpressionChars[context.Position++];

                if (op == chSensitive)
                {
                    OutputID(context, oID, chSensitive.ToString() + chSensitive.ToString(), nPos);
                    context.Position++;
                }

                node2 = doNextOP(context);

                node = NewTreeNode(context, node1, node2, oID, nPos);

                node1 = node;
            }

            return(node1);
        }
コード例 #26
0
        /// <summary>
        /// 逻辑比较运算
        /// </summary>
        /// <returns></returns>
        private ExpTreeNode DoLogicalOP(ParsingContext context)
        {
            ExpTreeNode node  = null;
            ExpTreeNode node1 = DoAddSub(context);
            ExpTreeNode node2 = null;

            char op = context.CurrentChar;

            string strID = string.Empty;

            while (op == '>' || op == '<' || op == '=')
            {
                int nPos = context.Position;

                Operation_IDs oID = Operation_IDs.OI_NONE;

                if (context.ExpressionChars[++context.Position] == '=')
                {
                    switch (op)
                    {
                    case '>':           //>=
                        oID   = Operation_IDs.OI_GREATEQUAL;
                        strID = ">=";
                        break;

                    case '<':           //<=
                        oID   = Operation_IDs.OI_LESSEQUAL;
                        strID = "<=";
                        break;

                    case '=':           //==
                        oID   = Operation_IDs.OI_EQUAL;
                        strID = "==";
                        break;

                    default:
                    {
                        if (context.ThrowParseException)
                        {
                            throw ParsingException.NewParsingException(ParseError.peInvalidOperator,
                                                                       context.Position, op.ToString());
                        }
                        break;
                    }
                    }

                    context.Position++;
                }
                else
                {
                    if (context.CurrentChar == '>')
                    {
                        if (op == '<')  //<>
                        {
                            strID = "<>";
                            oID   = Operation_IDs.OI_NOT_EQUAL;
                            context.Position++;
                        }
                        else
                        {
                            if (context.ThrowParseException)
                            {
                                throw ParsingException.NewParsingException(ParseError.peInvalidOperator,
                                                                           context.Position, op.ToString());
                            }
                        }
                    }
                    else
                    {
                        switch (op)
                        {
                        case '>':
                            oID   = Operation_IDs.OI_GREAT;
                            strID = ">";
                            break;

                        case '<':
                            oID   = Operation_IDs.OI_LESS;
                            strID = "<";
                            break;

                        default:
                        {
                            if (context.ThrowParseException)
                            {
                                throw ParsingException.NewParsingException(ParseError.peInvalidOperator,
                                                                           context.Position, op.ToString());
                            }

                            break;
                        }
                        }
                    }
                }

                OutputID(context, oID, strID, nPos);

                node2 = DoAddSub(context);

                node = NewTreeNode(context, node1, node2, oID, nPos);

                node1 = node;

                op = context.CurrentChar;
            }

            return(node1);
        }
コード例 #27
0
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="oID"></param>
		/// <param name="strID"></param>
		/// <param name="nPos"></param>
		/// <param name="prev"></param>
		public ParseIdentifier(Operation_IDs oID, string strID, int nPos, ParseIdentifier prev)
		{
			_OperationID = oID;
			_Identifier = strID;
			_Position = nPos;
			_PrevIdentifier = prev;
		}
コード例 #28
0
        private static void OutputID(ParsingContext context, Operation_IDs oID, string strID, int nPos)
        {
            if (context.OutputIdentifiers)
            {
                ParseIdentifier pi = new ParseIdentifier(oID, strID, nPos, context.CurrentIdentifier);

                if (context.CurrentIdentifier == null)
                {
                    if (context.ParentIdentifier == null)
                        context.Identifiers = pi;
                    else
                        context.ParentIdentifier.SubIdentifier = pi;
                }
                else
                    context.CurrentIdentifier.NextIdentifier = pi;

                pi.ParentIdentifier = context.ParentIdentifier;
                context.CurrentIdentifier = pi;
            }
        }
コード例 #29
0
        private ExpTreeNode GetFunctionNode(ParsingContext context, Operation_IDs funcID, string strID)
        {
            ExpTreeNode        node      = null;
            ExpTreeNode        nodeTemp  = null;
            List <ExpTreeNode> paramBase = new List <ExpTreeNode>(4);

            int nStartFunction = context.Position - strID.Length;

            OutputID(context, Operation_IDs.OI_USERDEFINE, strID, nStartFunction);

            if (context.CurrentChar == '(')     //有参数
            {
                OutputIDToSubLevel(context);
                OutputID(context, Operation_IDs.OI_LBRACKET, "(", context.Position);

                do
                {
                    context.Position++;
                    SkipSpaces(context);

                    nodeTemp = DoExpression(context);

                    if (nodeTemp != null)
                    {
                        paramBase.Add(nodeTemp);

                        SkipSpaces(context);
                    }
                    else
                    {
                        break;
                    }

                    if (context.CurrentChar == ',')
                    {
                        OutputID(context, Operation_IDs.OI_COMMA, ",", context.Position);
                    }
                }while (context.CurrentChar == ',');

                if (context.CurrentChar == ')')
                {
                    OutputID(context, Operation_IDs.OI_RBRACKET, ")", context.Position);
                    OutputIDToParentLevel(context);

                    context.Position++;
                    node             = NewTreeNode(context);
                    node.Position    = nStartFunction;
                    node.Params      = paramBase;
                    node.OperationID = funcID;

                    if (funcID == Operation_IDs.OI_USERDEFINE)
                    {
                        node.FunctionName = strID;
                    }
                }
                else
                {
                    if (context.ThrowParseException)
                    {
                        throw ParsingException.NewParsingException(ParseError.peCharExpected, context.Position, ")");
                    }
                }

                SkipSpaces(context);
            }
            else        //没有参数
            {
                node             = NewTreeNode(context);
                node.Position    = nStartFunction;
                node.Params      = paramBase;
                node.OperationID = funcID;

                if (funcID == Operation_IDs.OI_USERDEFINE)
                {
                    node.FunctionName = strID;
                }
            }

            return(node);
        }
コード例 #30
0
        private static ExpTreeNode DoLogical_AND_OR(ParsingContext context, char chSensitive, Operation_IDs oID, Func<ParsingContext, ExpTreeNode> doNextOP)
        {
            ExpTreeNode node = null;
            ExpTreeNode node1 = doNextOP(context);
            ExpTreeNode node2 = null;

            while (context.CurrentChar == chSensitive)
            {
                int nPos = context.Position;
                char op = context.ExpressionChars[context.Position++];

                if (op == chSensitive)
                {
                    OutputID(context, oID, chSensitive.ToString() + chSensitive.ToString(), nPos);
                    context.Position++;
                }

                node2 = doNextOP(context);

                node = NewTreeNode(context, node1, node2, oID, nPos);

                node1 = node;
            }

            return node1;
        }