Java Reference
In-Depth Information
8. Suppose that the terminals assign, deref,andaddr correspond to the
input symbols =,
,and&, respectively. Using the grammar in Figure 7.20
show parse trees for the following strings;
show where indirections actually occur by circling the parse tree
nodes that correspond to the rule R
L.
(a) x=y
(b) x= y
(c)
x=y
(d)
x=
y
(e)
x=&y
(f)
16 = 256
9. Construct an LL(1) grammar for the language in Figure 7.14.
10. Consider extending the grammar in Figure 7.14 to include binary sub-
traction and unary negation, so that the expression
minus y minus x times 3
has the e
ff
ect of negating y prior to subtraction of the product of x and 3.
(a) Following the steps outlined in Section 7.4, modify the grammar
to include these new operators. Your grammar should grant nega-
tion strongest precedence, at a level equivalent to deref.Binary
subtraction can appear at the same level as binary addition.
(b) Modify the chapter's AST design to include subtraction and nega-
tion by including a minus operator node.
(c) Install the appropriate semantic actions into the parser.
11. Modify the grammar and semantic actions of Figure 7.3 so that the rule for
Digs is right recursive. Your semantic actions should create the identical
AST.
 
Search WWH ::




Custom Search