Ejemplo n.º 1
0
        public override Expression VisitConditional_and_expression([NotNull] calculatorParser.Conditional_and_expressionContext context)
        {
            if (context.children != null)
            {
                foreach (IParseTree c in context.children)
                {
                    Visit(c);
                }
            }
            if (context.ChildCount == 0)
            {
                Results[context] = null;
                return(null);
            }
            Expression lhs = Results[context.GetChild(0)];

            if (context.ChildCount == 1)
            {
                Results[context] = lhs;
                return(lhs);
            }
            int count = 0;

            for (; count < context.ChildCount;)
            {
                // LHS partially computed.

                // Get op.
                string op = "";
                if (count + 1 < context.ChildCount)
                {
                    IParseTree op_pt = context.GetChild(count + 1);
                    op = op_pt.GetText();
                }

                // Get RHS, and update LHS.
                if (count + 2 < context.ChildCount && _completeness.Results[context.GetChild(count + 2)])
                {
                    Expression rhs = Results[context.GetChild(count + 2)];
                    if (op == "&&")
                    {
                        lhs = Expression.And(lhs, rhs);
                    }
                }

                count += 2;
            }
            Results[context] = lhs;
            return(lhs);
        }
Ejemplo n.º 2
0
        public override bool VisitConditional_and_expression([NotNull] calculatorParser.Conditional_and_expressionContext context)
        {
            bool res = false;

            if (context.children != null)
            {
                foreach (IParseTree c in context.children)
                {
                    if (!Visit(c))
                    {
                        Results[context] = false;
                        return(false);
                    }
                }
            }
            if (context.ChildCount == 0)
            {
                Results[context] = res;
                return(res);
            }
            bool lhs = Results[context.GetChild(0)];

            if (context.ChildCount == 1)
            {
                Results[context] = lhs;
                return(lhs);
            }
            int count = 0;

            res = lhs;
            for (; count < context.ChildCount && count + 2 < context.ChildCount;)
            {
                bool rhs = Results[context.GetChild(count + 2)];
                res   &= rhs;
                count += 2;
            }
            Results[context] = res;
            return(res);
        }