next up previous
Next: About this document ... Up: Quiz11 Previous: Exercise 3.

Exercise 4.

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 4  


next up previous
Next: About this document ... Up: Quiz11 Previous: Exercise 3.
Marc Moreno Maza
2004-12-02