SDD for Simple Type Declarations

The SDD in Fig. 5.8 is used for declarations of the form:

T id1, id2, id3;
Where:
  • T is a type (int or float)
  • Followed by a comma-separated list of identifiers

Explanation:

  • T.type is a synthesized attribute that carries the type (int or float)
  • L.inh is an inherited attribute passed from the type T to all identifiers in the list L
  • The addType() function is used to store the type info of each identifier in the symbol table.

Example: int id1, id2, id3;

Parsing this using the productions:

D → T L
T → int → T.type = integer
L → L1 , id3
L1 → L2 , id2
L2 → id1

Here, L.inh = integer, and each addType(id.entry, L.inh) assigns the type integer to id1, id2, and id3.

Dependency Graph for int id1, id2, id3

Graph Nodes Explained:

Node No.Represents
1id1.entry
2id2.entry
3id3.entry
4T.type = integer
5,7,9L.inh at each level (copied from T.type)
6,8,10addType(id1.entry, integer) and so on

The type is propagated downward through L.inh attributes
Each addType() operation depends on both the identifier and the type value.

Leave a Reply

Your email address will not be published. Required fields are marked *