Example #1
0
        //Evaluate the check fragment for the full check.
        public override object VisitCheckfrag([NotNull] algoParser.CheckfragContext context)
        {
            //Evaluate the expressions on the left and right, depending on the operator.
            if (context.GRTR_THAN() != null)
            {
                // Binary greater than.
                //Evaluate both the expressions.
                AlgoValue left  = (AlgoValue)VisitExpr(context.expr()[0]);
                AlgoValue right = (AlgoValue)VisitExpr(context.expr()[1]);

                return(new AlgoValue()
                {
                    Type = AlgoValueType.Boolean,
                    Value = AlgoComparators.GreaterThan(context, left, right, false),
                });
            }
            else if (context.GRTR_THAN_ET() != null)
            {
                // Binary greater than or equal to.
                //Evaluate both the expressions.
                AlgoValue left  = (AlgoValue)VisitExpr(context.expr()[0]);
                AlgoValue right = (AlgoValue)VisitExpr(context.expr()[1]);

                return(new AlgoValue()
                {
                    Type = AlgoValueType.Boolean,
                    Value = AlgoComparators.GreaterThan(context, left, right, true),
                });
            }
            else if (context.LESS_THAN() != null)
            {
                // Binary less than.
                //Evaluate both the expressions.
                AlgoValue left  = (AlgoValue)VisitExpr(context.expr()[0]);
                AlgoValue right = (AlgoValue)VisitExpr(context.expr()[1]);

                return(new AlgoValue()
                {
                    Type = AlgoValueType.Boolean,
                    Value = AlgoComparators.LessThan(context, left, right, false),
                });
            }
            else if (context.LESS_THAN_ET() != null)
            {
                // Binary less than or equal to.
                //Evaluate both the expressions.
                AlgoValue left  = (AlgoValue)VisitExpr(context.expr()[0]);
                AlgoValue right = (AlgoValue)VisitExpr(context.expr()[1]);

                return(new AlgoValue()
                {
                    Type = AlgoValueType.Boolean,
                    Value = AlgoComparators.LessThan(context, left, right, true),
                });
            }
            else if (context.BIN_EQUALS() != null)
            {
                //Binary EQUALS.
                //Evaluate the left and right values.
                AlgoValue left  = (AlgoValue)VisitExpr(context.expr()[0]);
                AlgoValue right = (AlgoValue)VisitExpr(context.expr()[1]);

                //Return whether these two are equal, as AlgoValue.
                return(new AlgoValue()
                {
                    Type = AlgoValueType.Boolean,
                    Value = AlgoComparators._Equals(context, left, right),
                });
            }
            else if (context.BIN_NET() != null)
            {
                //Binary not equal to.
                //Evaluate the left and right values.
                AlgoValue left  = (AlgoValue)VisitExpr(context.expr()[0]);
                AlgoValue right = (AlgoValue)VisitExpr(context.expr()[1]);

                //Return whether these two are equal, as AlgoValue.
                return(new AlgoValue()
                {
                    Type = AlgoValueType.Boolean,
                    Value = !AlgoComparators._Equals(context, left, right),
                });
            }
            else
            {
                //Only a single value, so evaluate and return.
                return((AlgoValue)VisitExpr(context.expr()[0]));
            }
        }
Example #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="algoParser.checkfrag"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitCheckfrag([NotNull] algoParser.CheckfragContext context)
 {
     return(VisitChildren(context));
 }
Example #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="algoParser.checkfrag"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCheckfrag([NotNull] algoParser.CheckfragContext context)
 {
 }