Java Reference
In-Depth Information
foreach AbstractNode n AST do
switch ( n . getType())
case IfNode
call f . visit(IfNode⇓ n )
case PlusNode
call f . visit(PlusNode⇓ n )
case MinusNode
call
f . visit(MinusNode⇓ n )
Figure 7.26: An alternative for achieving double dispatch.
18. Compute the location of each x and the total number of x symbols, as
in Exercise 17, using bottom-up parser with semantic actions. You may
restructure the grammar as you see fit, but use only synthesized attribute
flow.
19. Based on the discussion of Section 7.4 and using the pseudocode in
Figure 7.13 as a guide, design a set of AST classes andmethods to support
AST construction in a real programing language.
20. In contrast to the approach discussed in Section 7.7.2, Figure 7.25 shows
the partial results of a design in which each phase contributes code to
each node type.
(a) What are the advantages and disadvantages of the approach used
in Figure 7.25?
(b) How does the visitor pattern discussed in Section 7.7.2 address the
disadvantages?
21. In contrast with the approaches discussed in Sections 7.7.2 and 7.7.3,
consider the idea sketched in Figure 7.26.
(a) What are the advantages and disadvantages of the approach used
in Figure 7.26?
(b) How does the visitor pattern discussed in Sections 7.7.2 and 7.7.3
address the disadvantages?
 
Search WWH ::




Custom Search