public object visitExprLogicalExpr(ExprLogical expr) { object left = evaluate(expr.left); switch (expr.eOperator.type) { case TokenType.OR: if (isTruthy(left)) { return(left); } break; case TokenType.AND: if (!isTruthy(left)) { return(left); } break; case TokenType.QMARK: if (!isTruthy(left)) { return(null); } break; } return(evaluate(expr.right)); }
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); }
Expr logicAndExpr() { if (match(TokenType.AND)) { Token operatorExpr = previous(); Expr right = equalityExpr(); throw error(operatorExpr, "Expected expression before '" + operatorExpr.lexeme + "'."); } Expr expr = equalityExpr(); while (match(TokenType.AND)) { Token op = previous(); Expr right = equalityExpr(); expr = new ExprLogical(expr, op, right); } return(expr); }
public object visitExprLogicalExpr(ExprLogical expr) { resolve(expr.left); resolve(expr.right); return(null); }
public object visitExprLogicalExpr(ExprLogical expr) { return(parenthesize(expr.eOperator.lexeme, expr.left, expr.right)); }