
Consider the following two syntax-directed definitions and for type declarations.
is the start symbol, and int, float and id 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 put updates the symbol table with the type information for an identifier.
Let and be the languages specified by grammars and , respectively.
Which of the following statements is/are true?
View worked solution
Answer: A;B;D
Let us analyze each option step-by-step:
1. Language Equivalence (Option A):
- Grammar : The productions are , , and . This generates a type followed by one or more identifiers: .
- Grammar : The productions are and . This also generates a type followed by one or more identifiers: .
Since , Option A is true.
2. Attributes of SDD2 (Option B):
- The attributes defined in are and .
- is defined directly from terminals (synthesized).
- is defined using the attributes of its children ( or ), which are also synthesized.
- Since every attribute in is synthesized, it is S-attributed and contains only synthesized attributes. Thus, Option B is true.
3. Attributes of SDD1 (Option C):
- In , is an inherited attribute because its value in is defined as (inherited from sibling ).
- However, and are synthesized attributes. Since contains both synthesized and inherited attributes, the claim that it contains only inherited attributes is false. Thus, Option C is false.
4. Symbol Table Entries (Option D):
- For any declaration string like :
- In , the type is inherited down the parse tree through , and is called for every identifier.
- In , the type is synthesized up the parse tree through , and is called for every identifier.
- In both cases, the exact same identifier-to-type mappings are added to the symbol table. Thus, Option D is true.
Free practice · Your answers on this page are not saved.




