next up previous
Next: Exercise 3. Up: Quiz4 Previous: Exercise 1.

Exercise 2.

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 2  
\fbox{
\begin{minipage}{13 cm}
Observe that $offset$\ must be initialized before...
...1$\ & $\{ T.with$\ := $4 \}$\ \\ \hline
\end{tabular}\end{center}\end{minipage}}


next up previous
Next: Exercise 3. Up: Quiz4 Previous: Exercise 1.
Marc Moreno Maza
2004-12-02