Java Reference
In-Depth Information
class IfNode extends AbstractNode
procedure
type
C
heck
()
/
Type-checking code for an if
/
end
procedure
code
G
en
()
/
Generate code for an if
/
end
...
end
class PlusNode extends AbstractNode
procedure
type
C
heck
()
/
Type-checking code for a plus
/
end
procedure
code
G
en
()
/
Generate code for a plus
/
end
...
end
...
Figure 7.25: Inferior design: phase code distributed among node
types.
16. Figure 7.8(a) does not check that digits are within range of the specified
base. Insert semantic actions to perform such checks, rewriting the
grammar if necessary to support such checking as cleanly and concisely
as possible.
17. The semantic values shown in Figure 7.2(b) serve to count the position
of each x in a string.
(a) What grammar is implied by the parse tree of Figure 7.2(a)?
(b) Why is that grammar unsuitable for top-down parsing?
(c) Transform the grammar so that it is suitable for top-down parsing.
(d) Write a recursive-descent parser based on your grammar.
(e) Add semantic actions into the parser that compute the semantic
values as shown in Figure 7.2(b) using only inherited attribute flow.
(f) Add more semantic actions to your parser that return (synthesize)
the total number of x symbols found in the string.
 
Search WWH ::




Custom Search