Java Reference
In-Depth Information
7. Implement semantic actions in the recursive-descent parser for ac to
construct ASTs using the design guidelines in Section 2.6.
8. The grammar for ac shown in Figure 2.1 requires all declarations to
precede all executable statements. In this exercise, the ac language is
extended so that declarations and executable statements can be inter-
spersed. However, an identifier cannot be mentioned in an executable
statement until it has been declared.
(a) Modify the CFG in Figure 2.1 to accommodate this language exten-
sion.
(b) Discuss any revisions you would consider in the AST design for ac.
(c) Discuss how semantic analysis is a
ff
ected by the changes you envi-
sion for the CFG and the AST.
9. The abstract tree design for ac uses a single node to represent a print
operation (see Figure 2.9). Consider an alternative design in which the
print operation always has a single id child that represents the variable to
be printed. What are the design and implementation issues associated
with the two approaches?
10. The code in Figure 2.10 examines an AST node to determine its e
ect on
the symbol table. Explain why the order in which nodes are visited does
or does not matter with regard to symbol-table construction.
ff
11. Figure 2.6 scans an input stream for an inum or fnum based on the regular
expressions for those patterns shown in Figure 2.3. The code in Figure 2.6
does not check for errors.
(a) Where could errors occur in Figure 2.6?
(b) For each error, what action would you take should the error occur?
12. The last fragment of code generated in Figure 2.15 pops the dc stack and
stores the resulting value in register i.
(a) Why was register i chosen to receive the result?
(b) Which other registers could have been chosen without causing any
problems for code that might be generated subsequently?
 
Search WWH ::




Custom Search