Answer the following questions related to the implementation of a simple calcula
ID: 3820979 • Letter: A
Question
Answer the following questions related to the implementation of a simple calculator discussed in Chapter 3. (1) Show your understanding about the postfix() algorithm discussed in the lecture note and the textbook by showing how to convert the following 2 infix expressions into their postfix expression using a stack step by step. 9/3 - 2 + 4 * 2 - 1 * 6 (((a + b) * (c + d) + f) * g - h Show your understanding about the eval() algorithm by showing how you evaluate the first infix expression given in (1) using a stack step by step. Assume that you have to handle plus and minus and signs ONLY, for example, -2 - +1 + 4 - 3. Show a pseudo code on how you evaluate such infix expressions with explanations.Explanation / Answer
In any assembly language program
(((a+b)*(c+d))+f)*g-h
push h // stack ==> h
push b // Stack ==> b, h
push a // Stack ==> a, b, h
add // Stack ==> (a+b), h
push c // Stack ==> c, (a+b), h
push d // Stack ==> d, c, (a+b), h
add // Stack ==> (d+c), (a+b), h
mul // Stack ==> ((d+c)*(a+b)), h
push f // Stack ==> f,((d+c)*(a+b)), h
add // Stack ==> (f+((d+c)*(a+b))), h
push g // Stack ==> g, (f+((d+c)*(a+b))), h
mul // Stack ==> g*(f+((d+c)*(a+b))), h
sub // Stack ==> g*(f+((d+c)*(a+b)))- h
infix into postfix algorithm
When operators have the same precedence, we must consider association. Left to right association means that the operator on the stack must be done first, while right to left association means the reverse.
(((a+b)*(c+d))+f)*g-h ==
A B + C D + * F + G * H -
9 / 3 - 2 + 4 * 2 - 1 * 6 ==
9 3 / 4 2 * 1 6 * 3 1 4 - - +
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.