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 |
|
namelist attriblist |
namelist |
|
, namelist |
namelist |
|
|
attriblist |
|
A attriblist |
attriblist |
|
A |
A |
|
|
A |
|
|
A |
|
|
A |
|
|
A |
|
|
|
|
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