private Expression And() { var expression = Equality(); while (Match(TokenType.And)) { var token = Previous(); var right = Equality(); expression = new Expression.Logical(expression, token, right); } return(expression); }
private Expression Or() { var expression = And(); while (Match(TokenType.Or)) { var token = Previous(); var right = And(); expression = new Expression.Logical(expression, token, right); } return(expression); }
public object VisitLogical(Expression.Logical expression) { var left = Evaluate(expression.Left); if (expression.Operator.Type == TokenType.Or) { if (IsTruthy(left)) { return(left); } } else { if (!IsTruthy(left)) { return(left); } } return(Evaluate(expression.Right)); }
public string VisitLogical(Expression.Logical expression) { return(Parenthesize(expression.Left.Accept(this) + expression.Operator.Lexeme + expression.Right.Accept(this))); }