Skip to content
GATEiit

GATE CSE 2019 Q46: Placeholders for inherited type attributes in a declaration grammar

Syllabus topic: Lexical analysis, parsing and syntax-directed translation

Question

Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1,X2,X3,X4,X5, and X6 be the placeholders for the non-terminals D, T, L or L1 in the following table:

Production ruleSemantic action
D→T LX1.type = X2.type
T→ intT.type = int
T→ floatT.type = float
L→L1 , idX3.type = X4.type; addType(id.entry, X5.type)
L→ idaddType(id.entry, X6.type)

Which one of the following are the appropriate choices for X1,X2,X3 and X4?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: A (official GATE 2019 final answer key)

Concept used: An inherited attribute flows from a parent or left sibling to a child: the type computed at T is passed to L, and then from L down to L1 in the list.

Concept notes

Loading notes…

First step: In D→T L the type is known at T and must be handed to L; in L→L1,id decide which of L and L1 already holds the type and which one receives it.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Lexical analysis, parsing and syntax-directed translation

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key