public object VisitTertiaryExpr(Expr.Tertiary expr) { var condition = Evaluate(expr.Condition); if (IsTruthy(condition)) { return(Evaluate(expr.Then)); } else { return(Evaluate(expr.Else)); } }
private Expr Expression() { Expr expr = Equality(); if (Match(TokenType.IfThen)) { Expr then = Expression(); Consume(TokenType.Else, "Expected ':' after then-branch of ?."); Expr @else = Expression(); expr = new Expr.Tertiary(expr, then, @else); } return(expr); }
public string VisitTertiaryExpr(Expr.Tertiary expr) { return($"{expr.Condition.Accept(this)} ? {expr.Then.Accept(this)} : {expr.Else.Accept(this)}"); }
public string VisitTertiaryExpr(Expr.Tertiary expr) { return(Parenthesize("?:", expr.Condition, expr.Then, expr.Else)); }