Beispiel #1
0
        //(expr )? expr2  : expr3
        private Expr Ternary()
        {
            var expr = Equality();

            while (Match(QUESTION))
            {
                var expr2 = Expression();
                var token = Consume(SEMICOLON, " Conditional missing ':' operator");
                var expr3 = Ternary();
                expr = new Expr.Ternary(expr, expr2, expr3);
            }
            return(expr);
        }
Beispiel #2
0
        /// <summary>
        /// ternary -> equality ("?" expression ":" ternary)?
        /// </summary>
        /// <returns></returns>
        private Expr Ternary()
        {
            Expr expr = this.Equality();

            if (match(QUESTION))
            {
                Expr thenC = this.Expression();
                Consume(COLON, "Expect ':' and yet none was forth coming");
                Expr elseBranch = Ternary();
                expr = new Expr.Ternary(expr, thenC, elseBranch);
            }

            return(expr);
        }
Beispiel #3
0
 public string VisitTernary(Expr.Ternary expr) => Parenthesize("conditional", expr.cond, expr.@true, expr.@false);
Beispiel #4
0
 public string VisitTernaryExpr(Expr.Ternary expr) => $"({expr.Expression.Accept(this)} ? {expr.IfTrue.Accept(this)} : {expr.IfFalse.Accept(this)})";
Beispiel #5
0
 public string VisitTernary(Expr.Ternary expr) => Printer("conditional", expr.cond, expr.@true, expr.@false);