GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 18

Inherited attributes during bottom-up parsing

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 2003 paper

GATE 2003, Q18 1 mark · MCQ
Report issue

Semantic Analysis & Type Checking

Question 18, GATE 2003: In bottom-up evaluation of a syntax-directed definition, inherited attributes can: A. Always be evaluated; B. Be evaluated only if the definition is L-attributed; C. Be evaluated only if the definition has synthesized attributes; D. Never be evaluated. Discuss the usual parsing-time interpretation and its limitation.
Tap to enlarge
Your answer
Answer & solution

Answer: B under a restricted one-pass evaluation model (no official key was published)

1. A synthesized attribute flows from children to parent and is naturally evaluated when a bottom-up parser reduces a production. An inherited attribute flows from parent or siblings toward a child and may be needed before that child is reduced. Therefore identify which dependency schedule the question permits before selecting an option.

2. Inherited attributes cannot in general be computed by the simple reduce-only mechanism used for synthesized attributes. In the usual left-to-right one-pass implementation, usable inherited information must be available from the parent context and already processed left siblings, the L-attributed dependency condition behind B. Even then suitable scheduling/marker productions or stack access may be needed; being L-attributed is not a blanket guarantee for every unmodified LR evaluation scheme. If bottom-up evaluation instead allows building a full parse/dependency graph and later scheduling arbitrary acyclic dependencies, L-attributedness is not necessary. The choice therefore depends on the conventional parsing-time model, which the prompt does not spell out.

Original paper, page 2