GATE / CS ARCHIVE

GATE CSE 2024 SET 2 / QUESTION 29

Recognize the false attribute-evaluation claims

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 2024 Set 2 paper

GATE 2024 Set 2, Q29 1 mark · MSQ
Report issue

Semantic Analysis & Type Checking

Question 29, GATE 2024: Select FALSE statements. A an attribute grammar is an SDD whose semantic functions have no side effects; B L-attributed definitions cannot always be evaluated depth first; C synthesized attributes can be evaluated during bottom-up parsing; D every L-attributed definition on an LR(1) grammar can be evaluated by bottom-up parsing.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, D

Approach: Check the allowed dependency direction and distinguish a completed-tree traversal from evaluation during parsing.

1. Derivation. The question asks for false statements. A is the usual side-effect-free definition of an attribute grammar. L-attributed definitions admit a left-to-right depth-first evaluation, assigning inherited attributes on entry and synthesized ones on return, so B is false. Synthesized attributes can be computed at reductions, making C true. Arbitrary inherited dependencies in an L-attributed definition need not be available at the relevant point in an LR parse, so D’s universal claim about evaluation during bottom-up parsing is false. Thus B, D. Constructing a full parse tree and doing a separate attribute-evaluation traversal is distinct from the intended parsing-time claim.

2. Explanation and checks. An L-attributed production restricts an inherited attribute of a child to information available from the parent and earlier siblings. A left-to-right depth-first traversal can therefore compute it before entering that child and compute synthesized values after returning. A bottom-up reduction naturally has child synthesized values available, but arbitrary inherited context may be required earlier than that reduction. Hence an LR(1) grammar alone does not ensure the claimed parsing-time attribute evaluation. The question asks for the false choices, not the true ones.

Original paper, page 20 · Answer key