public object Visit(Ternary expr) { Resolve(expr.cond); Resolve(expr.left); Resolve(expr.right); return(null); }
public object Visit(Ternary expr) { object cond = Evaluate(expr.cond); if (CheckIsTruthy(cond)) { return(Evaluate(expr.left)); } else { return(Evaluate(expr.right)); } }
Expr TernaryRule() { Expr expr = OrRule(); //handle ternary operator if (Match(QUESTION)) { Expr left = ExpressionRule(); Consume(COLON, "Expected ':' in ternary operator"); Expr right = ExpressionRule(); expr = new Ternary(expr, left, right); } return(expr); }