コード例 #1
0
        public UnifiedElement VisitConditionalExpression(
            ConditionalExpression expr, object data)
        {
            var cond   = expr.Condition.TryAcceptForExpression(this);
            var former = expr.TrueExpression.TryAcceptForExpression(this);
            var latter = expr.FalseExpression.TryAcceptForExpression(this);

            return(UnifiedTernaryExpression.Create(cond, former, latter));
        }
コード例 #2
0
        public static UnifiedExpression CreateConditionalExpression(
            XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "conditional_expression");

            /*
             * conditional_expression
             * : logical_or_expression ('?' expression ':' conditional_expression)?
             */

            if (node.Elements().Count() == 1)
            {
                return(CreateLogicalOrExpression(node.FirstElement()));
            }

            return(UnifiedTernaryExpression.Create(
                       CreateLogicalOrExpression(node.ElementAt(0)),
                       CreateExpression(node.NthElement(2)).First(),
                       CreateConditionalExpression(node.NthElement(4))));
        }