Mon, 16th Nov 2015, 02:33 Re: Program Lab 3

```

I know most of you have relegated lab 3 to history by now, but I thought
my response to a student might be useful to you all in the future.  I am
still answering student email about lab 3 even though it is now after 2am.
Too late for this assignment, but perhaps not too late for increasing
knowledge.

In any case, a student writes:

> Good Afternoon Dr. Patt,
>
> I am a student in your EE306 course and feel I am currently overthinking
> the third program lab.
>
> I have most of the core program written, yet my issues come with the test
> for the character to be placed onto the stack. My first method was simply
> to compare the value of the ASCII for ) with the negative (xFFD7). If their
> sum is zero, then the character is ),

Good!

> values should be popped off the
> stack, operations should be performed and result pushed back onto the
> stack.

Good again!

> However, in the case of "y=(2-((5*8)+1))", the equation will be
> reduced to "y=(2-41)". Comparing the value 41 will give a false answer to
> the ASCII ")" test.

> Thanks,
>
> <<name withheld to protect the student who is looking for too many ")" >>

Why are you comparing 41 with the ascii code for ).  Before getting there,
you had (,2,-,(,40,+,1 on the stack.  You popped 1,+,40,( off the stack.
Then you did the operation, got the result 41 and pushed it on the stack.
There is no ) parenthesis to check here.  Now your stack looks like
(,2,-,41 on the stack.  ...and you look at the next input character, which is
a ), so you pop off those four values, perform the operation, getting -39.
The input is done, the stack is empty, you put -39 in the right place and
you are done.

Hope this helps.  See you in class.

Yale Patt

```