COMPUTER SCIENCE AND ENGINEERING
COMPILER DESIGN
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
postfix
|
|
prefix
|
|
both
|
|
polish
|
Detailed explanation-1: -Stack data structure is suitable for evaluating postfix expression. Stack : Stack is a linear data structure in which elements are inserted and deleted from one end only i.e. top of the stack. It follows a order to insert the elements into stack which is known as LIFO (Last in first out).
Detailed explanation-2: -Evaluation of postfix expression If it is a digit then, push it on to the stack. If it is an operator then, pop out the top most two contents from the stack and apply the operator on them. Later on, push the result on to stack. If the input symbol is ‘’, empty the stack.
Detailed explanation-3: -Step 1: Create an operand stack. Step 2: If the character is an operand, push it to the operand stack. Step 3: If the character is an operator, pop two operands from the stack, operate and push the result back to the stack. Step 4:After the entire expression has been traversed, pop the final result from the stack.