예제 #1
0
        public override Value VisitAnd_stat(calculatorParser.And_statContext context)
        {
            IReadOnlyList <calculatorParser.Condition_blockContext> conditions = context.condition_block();
            Value evaluateFinal = Visit(context.expr());
            bool? result        = null;

            foreach (var condition in conditions)
            {
                Value evaluateBody = Visit(condition.expr());
                if (evaluateBody.asBoolean() == true && evaluateFinal.asBoolean() == true)
                {
                    result = true;
                }
                if (evaluateBody.asBoolean() == false || evaluateFinal.asBoolean() == false)
                {
                    result = false;
                    break;
                }
            }

            if (result == null)
            {
                throw new Exception("Unable to evalute whether block is true or false");
            }

            return(new Value(result));
        }
예제 #2
0
        //STATEMENTS
        public override Value VisitAnd_stat(calculatorParser.And_statContext context)
        {
            IReadOnlyList <calculatorParser.Condition_blockContext> conditions = context.condition_block();
            Value evaluateFinal = Visit(context.expr());
            bool  result        = evaluateFinal.asBoolean();

            foreach (var condition in conditions)
            {
                Value evaluateBody = Visit(condition.expr());
                //if (evaluateBody.asBoolean() == true || evaluateFinal.asBoolean() == true) continue;
                if (!evaluateBody.asBoolean() || !result)
                {
                    result = false;
                    break;
                }
            }
            return(new Value(result));
        }