Exemplo n.º 1
0
        private Expr And()
        {
            Expr expr = Equality();

            while (Match(TokenType.AND))
            {
                Token op    = Previous();
                Expr  right = Equality();
                expr = new Logical(expr, op, right);
            }

            return(expr);
        }
Exemplo n.º 2
0
        private Expr Or()
        {
            Expr expr = And();

            while (Match(TokenType.OR))
            {
                Token op    = Previous();
                Expr  right = And();
                expr = new Logical(expr, op, right);
            }

            return(expr);
        }
Exemplo n.º 3
0
        public object VisitLogicalExpr(Logical 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.º 4
0
 public string VisitLogicalExpr(Logical expr)
 {
     return(Parenthesize(expr.op.lexeme, expr.left, expr.right));
 }
Exemplo n.º 5
0
 public object VisitLogicalExpr(Logical expr)
 {
     Resolve(expr.left);
     Resolve(expr.right);
     return(null);
 }