Пример #1
0
        // Converts a list of binary elements into a binary tree
        public static BinaryExpressionElement CreateElement(IList childValues, Type elementType)
        {
            BinaryExpressionElement firstElement = Activator.CreateInstance(elementType) as BinaryExpressionElement;

            firstElement.Configure(childValues[0] as ExpressionElement, childValues[2] as ExpressionElement, childValues[1]);

            BinaryExpressionElement lastElement = firstElement;

            for (int i = 3; i <= childValues.Count - 1; i += 2)
            {
                BinaryExpressionElement element = Activator.CreateInstance(elementType) as BinaryExpressionElement;
                element.Configure(lastElement as ExpressionElement, childValues[i + 1] as ExpressionElement, childValues[i]);
                lastElement = element;
            }

            return(lastElement);
        }
        private void AddBinaryOp(Production node, Type elementType)
        {
            IList childValues = this.GetChildValues(node);

            if (childValues.Count > 1)
            {
                BinaryExpressionElement e = BinaryExpressionElement.CreateElement(childValues, elementType);
                node.AddValue(e);
            }
            else if (childValues.Count == 1)
            {
                node.AddValue(childValues[0]);
            }
            else
            {
                Debug.Assert(false, "wrong number of chilren");
            }
        }