Example #1
0
 public object Visit(Ternary expr)
 {
     Resolve(expr.cond);
     Resolve(expr.left);
     Resolve(expr.right);
     return(null);
 }
Example #2
0
        public object Visit(Ternary expr)
        {
            object cond = Evaluate(expr.cond);

            if (CheckIsTruthy(cond))
            {
                return(Evaluate(expr.left));
            }
            else
            {
                return(Evaluate(expr.right));
            }
        }
Example #3
0
        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);
        }