Exemplo n.º 1
0
        public object VisitTertiaryExpr(Expr.Tertiary expr)
        {
            var condition = Evaluate(expr.Condition);

            if (IsTruthy(condition))
            {
                return(Evaluate(expr.Then));
            }
            else
            {
                return(Evaluate(expr.Else));
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public string VisitTertiaryExpr(Expr.Tertiary expr)
 {
     return($"{expr.Condition.Accept(this)} ? {expr.Then.Accept(this)} : {expr.Else.Accept(this)}");
 }
Exemplo n.º 4
0
 public string VisitTertiaryExpr(Expr.Tertiary expr)
 {
     return(Parenthesize("?:", expr.Condition, expr.Then, expr.Else));
 }