Beispiel #1
0
 public object VisitTernaryExpr(Expr.Ternary expr)
 {
     Resolve(expr.condition);
     Resolve(expr.ifTrue);
     Resolve(expr.ifFalse);
     return(null);
 }
 public object VisitTernaryExpr(Expr.Ternary expr)
 {
     if (IsTruthy(Evaluate(expr.condition)))
     {
         return(Evaluate(expr.ifTrue));
     }
     return(Evaluate(expr.ifFalse));
 }
        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);
        }
Beispiel #4
0
 public string VisitTernaryExpr(Expr.Ternary expr)
 {
     return($"({expr.condition.Accept(this)} ? {expr.ifTrue.Accept(this)} : {expr.ifFalse.Accept(this)})");
 }