• Convert the following infix expression A + B*C-D/E*H into its equivalent postfix expression. SYMBOL POSTFIX STRING STACK A A + A B AB + + * AB +* C ABC +* - ABC*+ D ABC*+D / ABC*+D -/ E ABC*+DE -/ * ABC*+DE/ * H ABC*+DE/H * End of string ABC*+DE/H*- REMARKS The input is now empty. Pop the output symbols from the stack until it is empty.
Added by Andrea M.
Close
Step 1
Step 1: Initialize an empty stack and an empty postfix string. Show more…
Show all steps
Your feedback will help us improve your experience
Fatina Seck and 80 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Select the correct alternative from the given choices. Which of the following is essential for converting an infix to postfix form efficiently? (A) Operator stack (B) Operand stack (C) Both (A) and (B) (D) Parse tree
Programming and Data Structures
Linked Lists, Stacks and Queues
Convert the following expression into postfix notation: $a=\left(-a+2^{*} b\right) / a$ (A) $a a-2 b^{*}+a /=$ (B) $a-2 b a^{*} /+=$ (C) $a 2 b * a /+$ (D) $a 2 b-* a /+$
COMPILER DESIGN
INTERMEDIATE CODE GENERATION
Evaluate a short algebraic expression using code with three-operand instructions. The expression should have a minimum of three operands and 2 operators. Operands may be alpha or numeric. You may only use registers A through F, plus X and T. Registers A through F may not be changed, i.e. their values are fixed. Register T may be used as a temporary register, and Register X must contain the final answer. Show the postfix for the expression, and then use a stack to evaluate the expression. As an example, consider X = A + B + C * D. The three-operand instructions would be: ADD X, A, B MUL T, C, D ADD X, X, T The Postfix would be AB+CD*+ The stack would be: PUSH A onto the stack PUSH B onto the stack ADD (pop A & B, add them, and push the answer back on the stack) PUSH C onto the stack PUSH D onto the stack MUL (pop C & D, multiply them, and push the answer back on the stack) ADD (pop X & T, add them, and push the answer back on the stack) POP X off the stack It is important to note that operational hierarchy dictates that we first perform all arithmetic inside inner parentheses, then inside outer parentheses, then do multiplication and division operations before addition and subtraction operations.
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD