Shift-reduce parser consists of (a) input buffer (b) stack (c) parse table…

2019

Shift-reduce parser consists of

(a) input buffer

(b) stack

(c) parse table

Choose the correct option from those given below:

  1. A.

    (a) and (b) Only

  2. B.

    (a) and (c) Only

  3. C.

    (c) Only

  4. D.

    (a), (b) and (c)

Attempted by 226 students.

Show answer & explanation

Correct answer: D

Answer: All three components are required.

  • Input buffer: holds the remaining input symbols; the parser reads the next symbol from here.

  • Stack: stores grammar symbols and parser states so the parser can apply reductions based on the current context.

  • Parse table: provides the action and goto information (shift, reduce, accept, error) used to decide parser actions.

How it works (high-level):

  1. Look up the action using the state on top of the stack and the next input symbol from the input buffer.

  2. If the action is shift, push the input symbol and the new state onto the stack and consume the symbol from the input buffer.

  3. If the action is reduce, pop the right-hand side symbols and states, push the left-hand side nonterminal, and consult the goto table to push the new state.

  4. Repeat until the action is accept (successful parse) or error.

Because all three parts (input buffer, stack, and parse table) are needed for these steps, the correct answer is that the shift-reduce parser consists of the input buffer, the stack, and the parse table.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor