Пример #1
0
        private Expr or()
        {
            Expr expr = and();

            while (match(TokenType.OR))
            {
                Token _operator = previous();
                Expr  right     = and();
                expr = new Expr.logicalExpr(expr, _operator, right);
            }

            return(expr);
        }
Пример #2
0
        private Expr and()
        {
            Expr expr = equality();

            while (match(TokenType.AND))
            {
                Token _operator = previous();
                Expr  right     = ternaryExpression();
                expr = new Expr.logicalExpr(expr, _operator, right);
            }

            return(expr);
        }
Пример #3
0
        public object visitLogicalExpr(Expr.logicalExpr logicalExpr)
        {
            object left = evaluate(logicalExpr.left);

            if (logicalExpr._operator.type == TokenType.OR)
            {
                if (isTruthy(left))
                {
                    return(left);
                }
            }
            else
            {
                if (!isTruthy(left))
                {
                    return(left);
                }
            }
            return(evaluate(logicalExpr.right));
        }
Пример #4
0
 public object visitLogicalExpr(Expr.logicalExpr logicalExpr)
 {
     resolve(logicalExpr.left);
     resolve(logicalExpr.right);
     return(null);
 }
Пример #5
0
 public string visitLogicalExpr(Expr.logicalExpr logicalExpr)
 {
     return(parenthesize(logicalExpr._operator.lexeme, new Expr[] { logicalExpr.left, logicalExpr.right }));
 }