60.2k views
3 votes
3 Given the following grammar:

E→E+T∣T
T→T×F∣F
F→(E)∣n

The input string is n+n×n, draw shift-reduce parser derivation stack

User Khoamle
by
9.1k points

1 Answer

6 votes

Final answer:

The shift-reduce parser derivation stack for the input string 'n+n×n' is E.

Step-by-step explanation:

The given grammar is:

  • E → E + T | T
  • T → T * F | F
  • F → (E) | n

The input string is 'n+n×n', and we need to draw the shift-reduce parser derivation stack.

  1. Initially, the stack contains only the start symbol E.
  2. Shift the first symbol 'n' to the stack.
  3. The stack now contains 'n', so we reduce it to F.
  4. Shift the next symbol '+' to the stack.
  5. Shift the next symbol 'n' to the stack.
  6. The stack now contains F + n, so we reduce it to T.
  7. Shift the next symbol '×' to the stack.
  8. Shift the next symbol 'n' to the stack.
  9. The stack now contains T × n, so we reduce it to T.
  10. The stack now contains T + T × n, so we reduce it to E.
  11. The stack now contains E, which is the final reduced form.

Therefore, the shift-reduce parser derivation stack for the input string 'n+n×n' is E.

User Brian McCarthy
by
7.8k points