GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 1.6

Associativity encoded by recursion

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 1997 paper

GATE 1997, Q1.6 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 1.6, GATE 1997: Grammar X→X⊕Y|Y, Y→Z⊙Y|Z, Z→id. Determine associativity of⊕ and⊙.
Tap to enlarge
Your answer
Answer & solution

Answer: A: ⊕ left, ⊙ right (no official key was published)

In X→X⊕Y, additional⊕ operators are introduced inside the left X. Thus id⊕id⊕id groups as (id⊕id)⊕id. In Y→Z⊙Y, additional⊙ operators occur in the right Y, grouping id⊙id⊙id as id⊙(id⊙id). Therefore⊕ is left associative and⊙ right associative, A. The lower nonterminal level also makes⊙ bind more tightly, but precedence and associativity are distinct properties.

Original paper, page 1