Exemplo n.º 1
0
 public object VisitTernaryExpr(Expr.Ternary expr)
 {
     Resolve(expr.condition);
     Resolve(expr.ifTrue);
     Resolve(expr.ifFalse);
     return(null);
 }
Exemplo n.º 2
0
 public object VisitTernaryExpr(Expr.Ternary expr)
 {
     if (IsTruthy(Evaluate(expr.condition)))
     {
         return(Evaluate(expr.ifTrue));
     }
     return(Evaluate(expr.ifFalse));
 }
Exemplo n.º 3
0
        private Expr Ternary()
        {
            Expr expr = Equality();

            if (Match(QUESTION_MARK))
            {
                Expr condition = expr;
                Expr ifTrue    = Assignment();
                Consume(COLON, "Expecting ':'");
                Expr ifFalse = Assignment();
                expr = new Expr.Ternary(condition, ifTrue, ifFalse);
            }

            return(expr);
        }
Exemplo n.º 4
0
 public string VisitTernaryExpr(Expr.Ternary expr)
 {
     return($"({expr.condition.Accept(this)} ? {expr.ifTrue.Accept(this)} : {expr.ifFalse.Accept(this)})");
 }