Пример #1
0
        private ExpressionTreeNode ParseOr()
        {
            var node = ParseAnd();

            if (_tokenReader.Token != Token.Or)
            {
                return(node);
            }

            _tokenReader.NextToken();

            ExpressionTreeNode root = ExpressionTreeNode.CreateOr(node, ParseAnd());

            node = root;

            while (true)
            {
                if (_tokenReader.Token != Token.Or)
                {
                    return(root);
                }

                _tokenReader.NextToken();

                var child1 = node.Child2;

                node.Child2 = ExpressionTreeNode.CreateOr(child1, ParseAnd());

                node = node.Child2;
            }
        }
Пример #2
0
        /// <summary>
        /// AND(NOT,NOT) -> NOT(OR)
        /// </summary>
        /// <param name="node"></param>
        private static ExpressionTreeNode TwoNotInAndRule(ExpressionTreeNode node, ref int count)
        {
            if (node == null)
            {
                return(null);
            }

            if (node.Operation == "AND" && node.Child1.Operation == "NOT" && node.Child2.Operation == "NOT")
            {
                var andChild = ExpressionTreeNode.CreateOr(node.Child1.Child1, node.Child2.Child1);

                node = ExpressionTreeNode.CreateNot(andChild);

                count++;
            }

            return(node);
        }