Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//this is testing value = Evaluator.Evaluate(\"(((((AAAAA2 + 123)))))\", Lookup)

ID: 3876270 • Letter: #

Question

//this is testing

value = Evaluator.Evaluate("(((((AAAAA2 + 123)))))", Lookup); //223 expected

//yet it crashes due to the unhandeled extra parenthesis any help would be great, this is the code where it crashes, thanks.

if (")".Equals(token))
{ //closing parens, we need to evaluate inner

//Must contain at least two values on the stack or the closing paren is invalid
//if (valueStack.Count < 2)
//{
// throw new ArgumentException("Invalid formula, not enough values inside the parentheses.");
//}

//get the previous value
int prevValue = valueStack.Pop();
//now get the previous operator
String prevOperator = operatorStack.Pop();
while (!"(".Equals(prevOperator))
{

Explanation / Answer

Run the code till it reaches string length:

If '(' then just continue:

Then when we get some number (operand) push into stack

When we get some operator, Pop two elements from stack, eveluate them and again push into stack.

Hope it helps, Let me know if you ahve any doubts/Concerns