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

Exercise 2.

Some languages such as PL1 permit a list of names to be given a list of attributes. The grammar G below abstracts the problem.

D $\displaystyle \longmapsto$ namelist  attriblist$\displaystyle \bf ;$
namelist $\displaystyle \longmapsto$ $\displaystyle \bf id$, namelist
namelist $\displaystyle \longmapsto$ $\displaystyle \bf id$
attriblist $\displaystyle \longmapsto$ A  attriblist
attriblist $\displaystyle \longmapsto$ A
A $\displaystyle \longmapsto$ $\displaystyle \bf long$
A $\displaystyle \longmapsto$ $\displaystyle \bf double$
A $\displaystyle \longmapsto$ $\displaystyle \bf single$
A $\displaystyle \longmapsto$ $\displaystyle \bf integer$
A $\displaystyle \longmapsto$ $\displaystyle \bf float$
   

where D, namelist, attriblist and A are nonterminals and where id, long, double, single, integer, float and ; are terminals. As usual id is the identifier token. For instance each of the following lines is a declaration generated by G.
i, j single integer;
u, v, w double float;
Give a syntax-directed definition for declarations generated by G. Here are some hints.

Answer 2  
\fbox{
\begin{minipage}{12 cm}
\begin{center}
\begin{tabular}{llll}
D & $\longm...
...$\ $A.attrib$\ := {\bf float} $\}$\ \\
\end{tabular}\end{center}\end{minipage}}


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