| SDD1 | SDD2 | ||
|---|---|---|---|
| Grammar (G1) | Semantic Rules | Grammar (G2) | Semantic Rules |
is the start symbol, and , and are the three terminals. The non-terminal is the same as and the non-terminal is the same as . Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function updates the symbol table with the type information for an identifier.
Let P and Q be the languages specified by grammars G1 and G2, respectively.
Which of the following statements is/are true?
["A","B","D"]
Step-by-Step Solution
Insight: This is an attribute classification and language equivalence question. The key is to check each SDD for synthesized vs. inherited attributes and trace the symbol table updates.
Exam route: Evaluate each statement against the definitions of S-attributed and L-attributed, and manually trace a sample string like "int id1 id2".
Learning route:
Statement A: "The languages P and Q are the same."
G1 generates: D → T V → int V → int V1 id → int id id.
G2 generates: D → D1 id → T id id → int id id.
Both generate a type followed by one or more identifiers. The languages are identical. TRUE.
Statement B: "SDD2 is S-attributed and contains only synthesized attributes."
In SDD2, D.type depends on D1.type or T.type (children). T.type depends on terminals. All attributes are synthesized. TRUE.
Statement C: "SDD1 is L-attributed and contains only inherited attributes."
In SDD1, V.type is inherited (from T), and V1.type is inherited (from V). However, T.type and D.type are synthesized. Since it contains synthesized attributes, "only inherited" is FALSE.
Statement D: "The specifications of SDD1 and SDD2 are such that the same entries get added to the symbol table."
For "int a b":
SDD1: V.type = int. V1.type = int. put(b.entry, int), then put(a.entry, int).
SDD2: D1.type = int. put(a.entry, int). Then put(b.entry, int).
The same entries (a:int, b:int) are added. TRUE.
Verification: Re-checking SDD1 confirms T.type is synthesized, invalidating Statement C. Statements A, B, and D hold.