next up previous
Next: Exercise 5. Up: Final-13-04-2004 Previous: Exercise 3.

Exercise 4.

The grammar below generates sequences of declarations of the form $ \bf id$ $ \bf :$ T.

P $\displaystyle \longmapsto$ D
D $\displaystyle \longmapsto$ D $\displaystyle \bf ;$ D
D $\displaystyle \longmapsto$ $\displaystyle \bf id$ $\displaystyle \bf :$ T
T $\displaystyle \longmapsto$ $\displaystyle \bf integer$
T $\displaystyle \longmapsto$ $\displaystyle \bf float$
T $\displaystyle \longmapsto$ $\displaystyle \bf array$ $\displaystyle \bf [$ $\displaystyle \bf num$ $\displaystyle \bf ]$ $\displaystyle \bf of$ T1
T $\displaystyle \longmapsto$ $\displaystyle \uparrow$ T1
   

As usual id is the token for identifiers, integer denotes a type of integers, float denotes a type of floating point numbers and num is the token for integer values. Note that array, $ \uparrow$, ; , :, [, ] and of are terminals too. Moreover, You are asked to write a translation scheme which computes the memory address of every declared name and stores this information in the symbol table. To reach that goal you may associate the nonterminal T with a synthesized attribute T.width that indicates the number of memory units taken by objects of type T. As usual, the nonterminal T has a synthesized attribute T.type. You are not asked to give the semantic rules computing T.type (although this is easy). You may need a global variable offset which gives the current available memory address:

Answer 4  


next up previous
Next: Exercise 5. Up: Final-13-04-2004 Previous: Exercise 3.
Marc Moreno Maza
2004-12-02