public object visitExprTernaryExpr(ExprTernary expr) { resolve(expr.top); resolve(expr.left); resolve(expr.right); return(null); }
private Expr ternaryConditionalExpr() { if (match(TokenType.QMARK)) { Token operatorExpr = previous(); Expr right = assignmentExpr(); if (match(TokenType.COLON)) { right = assignmentExpr(); } throw error(operatorExpr, "Expected expression before '" + operatorExpr.lexeme + "'."); } Expr expr = assignmentExpr(); if (match(TokenType.QMARK)) { Token operatorExpr1 = previous(); Expr leftExpr = assignmentExpr(); if (match(TokenType.COLON)) { Token operatorExpr2 = previous(); Expr rightExpr = assignmentExpr(); expr = new ExprTernary(expr, operatorExpr1, leftExpr, operatorExpr2, rightExpr); } else { expr = new ExprLogical(expr, operatorExpr1, leftExpr); } } return(expr); }
public object visitExprTernaryExpr(ExprTernary expr) { object top = evaluate(expr.top); switch (expr.topOperator.type) { case TokenType.QMARK: if (isTruthy(top)) { return(evaluate(expr.left)); } else { return(evaluate(expr.right)); } default: return(null); } }
public object visitExprTernaryExpr(ExprTernary expr) { return(parenthesize(expr.eOperator.lexeme + ' ' + expr.eOperator.lexeme, expr.top, expr.left, expr.right)); }