Next: Exercise 9.
Up: Final-2003
Previous: Exercise 7.
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$](img16.png) |
namelist attriblist![$\displaystyle \bf ;$](img52.png) |
namelist |
![$\displaystyle \longmapsto$](img16.png) |
, namelist |
namelist |
![$\displaystyle \longmapsto$](img16.png) |
![$\displaystyle \bf id$](img53.png) |
attriblist |
![$\displaystyle \longmapsto$](img16.png) |
A attriblist |
attriblist |
![$\displaystyle \longmapsto$](img16.png) |
A |
A |
![$\displaystyle \longmapsto$](img16.png) |
![$\displaystyle \bf long$](img54.png) |
A |
![$\displaystyle \longmapsto$](img16.png) |
![$\displaystyle \bf double$](img55.png) |
A |
![$\displaystyle \longmapsto$](img16.png) |
![$\displaystyle \bf single$](img56.png) |
A |
![$\displaystyle \longmapsto$](img16.png) |
![$\displaystyle \bf integer$](img57.png) |
A |
![$\displaystyle \longmapsto$](img16.png) |
![$\displaystyle \bf float$](img58.png) |
|
|
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.
- You may simply write N and T instead of namelist and
attriblist respectively.
- The code in the actions does not need to be C code but may be any pseudo-code
that is convenient to you.
- You may consider that id has an attribute
.name (as usual)
giving the lexical value of id.
- Moreover you may assume that every variable in the symbol table may be
associated with a list of attributes by an instruction like
enter(
.name, T.list)
- The instruction T.list := makelist(A.attrib) will
create the list consisting of the single item A.attrib.
- The instruction T.list := cons(A.attrib, T.list) will
add the element A.attrib at the beginning of the list T.list.
Answer 8
![\fbox{
\begin{minipage}{12 cm}
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \...
...\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\mbox{ } \\
\end{minipage}}](img10.png)
Next: Exercise 9.
Up: Final-2003
Previous: Exercise 7.
Marc Moreno Maza
2004-12-02