Java Reference
In-Depth Information
4. Consider the addition of the the rule
Expr
sum Values
to the grammar in Figure 7.9.
(a) Does this change make the grammar ambiguous?
(b) Is the grammar still LL(1) parseable?
(c) Show how the semantic actions in Figure 7.10 must be changed to
accommodate this new language construct; modify the grammar if
necessary but avoid use of global variables.
5. Consider the addition of the rule
Expr
mean Values
to the grammar in Figure 7.9. This rule defines an expression that com-
putes the average of its values, defined by:
v 1
+ v 2
+... v n
n
(mean v 1
... v n )
=
v 2
(a) Does this new rule render the grammar ambiguous?
(b) Is the grammar still LL(1) parseable?
(c) Describe your approach for syntax-directed translation of this new
construct.
(d) Modify the grammar of Figure 7.10 accordingly and insert the ap-
propriate semantic actions into Figure 7.10.
6. Although arithmetic expressions are typically evaluated from left to
right, the semantic actions in V
cause a product computed from
right to left. Modify the grammar and semantic actions of Figures 7.9
and 7.10 so that products are computed from left to right.
alues
7. Verify that the grammar in Figure 7.14 is unambiguous using an LALR(1)
parser generator.
Search WWH ::




Custom Search