Next: About this document ...
Up: Quiz11
Previous: Exercise 3.
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$](img8.png) |
namelist attriblist![$\displaystyle \bf ;$](img9.png) |
namelist |
![$\displaystyle \longmapsto$](img8.png) |
, namelist |
namelist |
![$\displaystyle \longmapsto$](img8.png) |
![$\displaystyle \bf id$](img10.png) |
attriblist |
![$\displaystyle \longmapsto$](img8.png) |
A attriblist |
attriblist |
![$\displaystyle \longmapsto$](img8.png) |
A |
A |
![$\displaystyle \longmapsto$](img8.png) |
![$\displaystyle \bf long$](img11.png) |
A |
![$\displaystyle \longmapsto$](img8.png) |
![$\displaystyle \bf double$](img12.png) |
A |
![$\displaystyle \longmapsto$](img8.png) |
![$\displaystyle \bf single$](img13.png) |
A |
![$\displaystyle \longmapsto$](img8.png) |
![$\displaystyle \bf integer$](img14.png) |
A |
![$\displaystyle \longmapsto$](img8.png) |
![$\displaystyle \bf float$](img15.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.
Next: About this document ...
Up: Quiz11
Previous: Exercise 3.
Marc Moreno Maza
2004-12-02