Example #1
0
        public ConditionalExpression(Conditional_expressionContext context, MethodBodySymbolContext methodBodySymbolContext, DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            _condition = new Lazy <IExpression>(BindCondition);
            _ifTrue    = new Lazy <IExpression>(BindIfTrue);
            _ifFalse   = new Lazy <IExpression>(BindIfFalse);
            _type      = new Lazy <IType>(BindType);
        }
        public override Expression VisitConditional_expression(Conditional_expressionContext context)
        {
            var expression = Visit(context.children[0]);

            if (context.expression().Any())
            {
                var expression1 = Visit(context.expression()[0]);
                var expression2 = Visit(context.expression()[1]);
                expression = Expression.Condition(expression, expression1, expression2);
            }
            return(expression);
        }
Example #3
0
        public override object VisitConditional_expression([NotNull] Conditional_expressionContext context)
        {
            if (context.OPEN_PARENTHESIS() != null)
            {
                _output.Append('(');
                VisitConditional_expression(context.conditional_expression()[0]);
                _output.Append(')');
            }
            else if (context.NOT() != null)
            {
                _output.Append('!');
                VisitConditional_expression(context.conditional_expression()[0]);
            }
            else if (context.comparison_operator() != null)
            {
                VisitConditional_expression(context.conditional_expression()[0]);

                var op = context.comparison_operator();
                if (op.GREATER_THAN() != null)
                {
                    _output.Append('>');
                }
                else if (op.GREATER_EQUAL() != null)
                {
                    _output.Append(">=");
                }
                else if (op.LESS_THAN() != null)
                {
                    _output.Append('<');
                }
                else if (op.LESS_EQUAL() != null)
                {
                    _output.Append("<=");
                }
                else if (op.EQUALS() != null)
                {
                    _output.Append("==");
                }

                VisitConditional_expression(context.conditional_expression()[1]);
            }
            else if (context.logical_operator() != null)
            {
                VisitConditional_expression(context.conditional_expression()[0]);

                var op = context.logical_operator();
                if (op.AND() != null)
                {
                    _output.Append("&&");
                }
                else if (op.OR() != null)
                {
                    _output.Append("||");
                }

                VisitConditional_expression(context.conditional_expression()[1]);
            }
            else
            {
                VisitExpression(context.expression());
            }

            return(null);
        }
Example #4
0
	public Conditional_expressionContext conditional_expression() {
		Conditional_expressionContext _localctx = new Conditional_expressionContext(_ctx, State);
		EnterRule(_localctx, 210, RULE_conditional_expression);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 1185; logical_or_expression();
			State = 1191;
			_la = _input.La(1);
			if (_la==QUESTION) {
				{
				State = 1186; Match(QUESTION);
				State = 1187; conditional_expression();
				State = 1188; Match(COLON);
				State = 1189; conditional_expression();
				}
			}

			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.ReportError(this, re);
			_errHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}