I am working on parentheses position validation in a string expression using C#. The expression looks like below.
"Loan no = 12345 AND Borrower First Name Contains Milena OR Buy Side Lock Date = 03/13/2016 AND Last Finished Milestone = Decisioned OR Subject Property State = NC AND Loan Amt > 50000"
Here 'AND' and 'OR' are the two different operations that can be performed between two conditions. We have API in C# to evaluate two conditions containing an operation.
With these things in place, the end users are allowed to place the parentheses from UI between two or more conditions in order to evaluate those conditions on priority basis. However UI allows them to put parentheses only at the beginning or end of a condition.
Let's say in the above example, if the user want to evaluate the second and third condition on priority basis he/she put the parentheses between them as shown below.
Loan no = 12345 AND (Borrower First Name Contains Milena OR Buy Side Lock Date = 03/13/2016) AND Last Finished Milestone = Decisioned OR Subject Property State = NC AND Loan Amt > 50000.
However the end user can put as many parentheses as he/she wants. Now in the above expression with parentheses in place between second and third conditions if the user tries to put the parentheses between first and second conditions the logic breaks as the second and third conditions are already in parentheses which needs to be evaluated first. In this case I want to prevent the user from putting the parentheses between first and second conditions.
I checked few articles in the net which helps me in identifying the number of left parentheses count are equal to number of right parentheses count. However that will not help me in identifying the above problem.
Does any one has any suggestions?