protected override void Visit(LogicalBindaryExpression exp) { // OR is the 3rd level if (exp.Operator == LogicalOperator.OR) { // Simply visit the 3rd OR level and build all ComparisonModels Visit(exp.Left); Visit(exp.Right); } if (exp.Operator == LogicalOperator.AND) { // Because this class only build for ONE condition at a time. // So if we encounter a AND expression, it must be the 2nd level, that is, the (ComparisonGroup AND ComparisonGroup) level Visit(exp.Left); BuildComparisonGroup(); Visit(exp.Right); BuildComparisonGroup(); } }
protected virtual void Visit(LogicalBindaryExpression exp) { Visit(exp.Left); Visit(exp.Right); }
void IExpressionVisitor.Visit(LogicalBindaryExpression exp) { Visit(exp); }
protected override void Visit(LogicalBindaryExpression exp) { Visit(exp.Left); // Check if we can get result by only checking left expression. // If yes, then the result in the stack is alreay the result. var leftResult = _results.Peek(); // A and B, if A is false, the result will always be false, no need to check B if (exp.Operator == LogicalOperator.AND && leftResult == false) { return; } // A or B, if A is true, the result will always be true, no need to check B if (exp.Operator == LogicalOperator.OR && leftResult == true) { return; } // Pop the result of the left expression _results.Pop(); // If we cannot get result by checking left expression, // then check right expression. // The final result is same as the result of the right expression. // For example, // A and B, if A is true, then final result = B // A or B, if A is false, then final result = B Visit(exp.Right); }
// term : factor [ AND factor ] private Expression Term() { var exp = Factor(); if (exp != null) { while (!_tokenzier.IsEndOfFile) { using (var lookahead = _tokenzier.BeginLookahead()) { var op = _tokenzier.NextToken(); if (op != null && op.Kind == TokenKind.AND) { var sourceLocation = _tokenzier.CurrentLocation; var right = Factor(); if (right != null) { lookahead.Accept(); exp = new LogicalBindaryExpression(exp, right, LogicalOperator.AND); } else { _context.AddError("Missing right operand for operator " + op.Kind + ".", sourceLocation); break; } } else { break; } } } } return exp; }