Beispiel #1
0
        public override Argument VisitRelationalExpression(CalcParser.RelationalExpressionContext context)
        {
            Argument arg1 = Visit(context.expression(0));
            Argument arg2 = Visit(context.expression(1));

            if (arg1.IsNull || arg2.IsNull)
            {
                return(Argument.Null);
            }

            if (context.GreaterThan() != null)
            {
                return(arg1.ToDouble() > arg2.ToDouble() ? new Argument(1.0) : new Argument(0.0));
            }

            if (context.GreaterThanEquals() != null)
            {
                return(arg1.ToDouble() >= arg2.ToDouble() ? new Argument(1.0) : new Argument(0.0));
            }

            if (context.LessThan() != null)
            {
                return(arg1.ToDouble() < arg2.ToDouble() ? new Argument(1.0) : new Argument(0.0));
            }

            if (context.LessThanEquals() != null)
            {
                return(arg1.ToDouble() <= arg2.ToDouble() ? new Argument(1.0) : new Argument(0.0));
            }

            throw new ExpressionException("Unknown relational operation: " + context.GetText());
        }
Beispiel #2
0
        public override Query VisitRelationalExpression(CalcParser.RelationalExpressionContext context)
        {
            Query q1 = Visit(context.expression(0));
            Query q2 = Visit(context.expression(1));

            if (context.GreaterThan() != null)
            {
                return(new Query($"({q1}>{q2})", ResultType.Number));
            }

            if (context.GreaterThanEquals() != null)
            {
                return(new Query($"({q1}>={q2})", ResultType.Number));
            }

            if (context.LessThan() != null)
            {
                return(new Query($"({q1}<{q2})", ResultType.Number));
            }

            if (context.LessThanEquals() != null)
            {
                return(new Query($"({q1}<={q2})", ResultType.Number));
            }

            throw new ExpressionException("Unknown relational expression: " + context.GetText());
        }