Java Reference
In-Depth Information
40. Recall the dangling else problem introduced in Chapter 5. A grammar
for a simplified language that allows conditional statements follows:
1 Start
Stmt $
2 Stmt
if e then Stmt else Stmt
3
|
if e then Stmt
4
|
other
ExplainwhythegrammarisorisnotLALR(1).
41. Consider the following grammar:
1 Start
Stmt $
2 Stmt
Matched
3
|
Unmatched
4 Matched
if e then Matched else Matched
5
|
other
6 Unmatched
if e then Matched else Unmatched
7
|
if e then Unmatched
(a) Explain why the grammar is or is not LALR(1).
(b) Is the language of this grammar the same as the language of the
grammar in Exercise 40? Why or why not?
42. Repeat Exercise 41, adding the production Unmatched
other to the
grammar.
43. Consider the following grammar:
1 Start
Stmt $
2 Stmt
Matched
3
|
Unmatched
4 Matched
if e then Matched else Matched
5
|
other
6 Unmatched
if e then Matched else Unmatched
7
|
if e then Stmt
(a) Explain why the grammar is or is not LALR(1).
(b) Is the language of this grammar the same as the language of the
grammar in Exercise 40? Why or why not?
 
Search WWH ::




Custom Search