Chapter 8: Intermediate Code Generation

Declarations

For each name create symbol table entry with information like type and relative address

P {offset=0} D  
D D ; D  
D id : T enter(id.name, T.type, offset);
  offset = offset + T.width
T integer T.type = integer; T.width = 4
T real T.type = real; T.width = 8
   

In the translation scheme nonterminal P generates a sequence of declarations of the form id : T . Before the first declaration is considered, offset is set to 0. As each new name is seen, that name is entered in the symbol table with the offset equal to the current value of offset, and offset is incremented by the width of the data object denoted by the name.

The procedure - enter (name, type, offset) creates a symbol-table entry for name , gives it type and relative address offset in its data area. We use synthesized attributes type and width for nonterminal T to indicate the type and Width, or number of memory units for nonterminal T to indicate the type and width, or number of memory units taken by objects of that type. If type expressions are represented by graphs, then attribute type might be a pointer to the node representing a type expression. We assume integers to have width of 4 and real to have width of 8. The width of an array is obtained by multiplying the width of each element by the number of elements in the array. The width of each pointer is also assumed to be 4.