Exemplo n.º 1
0
        public object VisitLogicalExpr(LogicalExpr expr)
        {
            Resolve(expr.Left);
            Resolve(expr.Right);

            return(null);
        }
Exemplo n.º 2
0
        // logic_and  → equality ( "and" equality )* ;
        private Expr And()
        {
            Expr expr = Equality();

            while (CheckCurrentToken(TokenType.And))
            {
                var  op    = GetCurrentTokenAndAdvance();
                Expr right = Equality();
                expr = new LogicalExpr(expr, op, right);
            }
            return(expr);
        }
Exemplo n.º 3
0
        // LogicalAnd -> Equality ( "and" Equality )*
        private AstNode LogicalAnd()
        {
            AstNode expr = Equality();

            while (Match(TokenType.AND))
            {
                Token   oper  = Previous();
                AstNode right = Equality();
                expr = new LogicalExpr(expr, oper, right);
            }

            return(expr);
        }
Exemplo n.º 4
0
        public object Visit_LogicalExpr(LogicalExpr expr)
        {
            Object left = Evaluate(expr.left);

            if (expr.op.type == TokenType.Or)
            {
                if (IsTruthy(left))
                {
                    return(left);
                }
            }
            else
            {
                if (!IsTruthy(left))
                {
                    return(left);
                }
            }

            return(Evaluate(expr.right));
        }
Exemplo n.º 5
0
        public object VisitLogicalExpr(LogicalExpr expr)
        {
            object left = Evaluate(expr.Left);

            // Short-circuiting logic
            if (expr.Oper.Type == TokenType.OR)
            {
                if (IsTruthy(left))
                {
                    return(left);
                }
            }
            else
            {
                if (!IsTruthy(left))
                {
                    return(left);
                }
            }

            return(Evaluate(expr.Right));
        }
Exemplo n.º 6
0
 public Void Visit_LogicalExpr(LogicalExpr expr)
 {
     Resolve(expr.left);
     Resolve(expr.right);
     return(null);
 }
Exemplo n.º 7
0
 public string Visit_LogicalExpr(LogicalExpr expr)
 {
     return(Parenthesize(expr.op.ToText(), expr.left, expr.right));
 }