Skip to content
Official PYQ · 1997

GATE CS 1997 Q1.6 — Parsing (LL, LR)

Explain with AI

In the following grammar

  • X::=X⊕Y∣YX ::= X \oplus Y \mid Y
  • Y::=Z∗Y∣ZY::= Z * Y \mid Z
  • Z::=idZ::= id

Which of the following is true?

Choose one option
View worked solution

Answer: A

To determine the associativity of the operators ⊕\oplus and ∗*, we analyze the recursive structure of the grammar rules:

  1. Operator ⊕\oplus: The production rule is: X→X⊕Y∣YX \to X \oplus Y \mid Y Since the non-terminal XX on the left-hand side appears as the leftmost symbol on the right-hand side of the production (X→X⊕YX \to X \oplus Y), this is a left-recursive production. Left-recursion implies that the operator ⊕\oplus is left-associative.
    Example: For the expression id⊕id⊕idid \oplus id \oplus id, the parse tree groups the leftmost operation first: ((id⊕id)⊕id)((id \oplus id) \oplus id).
  2. Operator ∗*: The production rule is: Y→Z∗Y∣ZY \to Z * Y \mid Z Since the non-terminal YY on the left-hand side appears as the rightmost symbol on the right-hand side of the production (Y→Z∗YY \to Z * Y), this is a right-recursive production. Right-recursion implies that the operator ∗* is right-associative.
    Example: For the expression id∗id∗idid * id * id, the parse tree groups the rightmost operation first: (id∗(id∗id))(id * (id * id)).

Therefore, ⊕\oplus is left-associative and ∗* is right-associative, which matches Option A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions