This is easy.... Count
If you get below zero then you have failed,
and if you get not-zero at the end you have failed.
You might want to check scope bridges. I.e.
(a{b+c)} which I would pass as fail.
but that is easy to modify the code below to include.
Example of pseudo code for JUST ( and ).
string A = "(expession) with ) ( ";
int b(0);
for(int i=0;i<A.length();i++)
{
if (A[i]=='(') b++;
if (A[i]==')')
{
b--;
if (b<0) failed();
}
}
if (b!=0) failed();
success();
[/code]
Additionally, I am sorry BUT you cannot use boolean values as suggested by freaky_chris since
the expression
((x+y)) would fail. And that is not acceptable.
Last edited by StuXYZ; Dec 5th, 2008 at 6:30 pm. Reason: added comment on freaky_chris's quicker comment.
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
Offline 659 posts
since Nov 2008