Esempio n. 1
0
        public override Expression VisitConditional_or_expression([NotNull] calculatorParser.Conditional_or_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.Or(lhs, rhs);
                    }
                }

                count += 2;
            }
            Results[context] = lhs;
            return(lhs);
        }
Esempio n. 2
0
        public override bool VisitConditional_or_expression([NotNull] calculatorParser.Conditional_or_expressionContext context)
        {
            bool res = false;

            Results[context] = res;
            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);
        }