Chapter 3
Chapter 3
G9:
1.IfStmt → Matched | Unmatched
2.Matched → if Cond then Matched else Matched |
OtherStmt
3.Unmatched → if Cond then Stmt | if Cond then
Matched else Unmatched
G11: 1. S → S B | a C
2. A → b S C a
3. B → a S B | b B C
4. C → a B C | a d
Solution:
1. Since C → a d, C is a generating symbol and
2. Since S → a C, S is also a generating symbol.
3. According to the production A → b S C a, A is also a generating symbol.
4. Right side of B → a S B and B → b B C contains B, and B is not
terminating, so B is not a generating symbol.
5. So, we can eliminate those productions and grammar becomes:
G11: 1. S → a C
2. A → b S C a
3. C → a d
Solution:
Since S is the start symbol and right side of S does not contain A, hence A
is not reachable as:
G11: 1. S → a C
2. C → a d
G12: I II
1. S → A B
3. B → C G12: 1. S → A B
2. A → a
4. C → D 2. A → a
3. B → C | b
5. D → E 3. B → a | b
4. C → D
4. C → a
5. D → E III
5. D → a
6. E → a G12: 1. S → A B
6. E → a
2. A → a
3. B → a | b
G13: 1. S → A B A C
1. S → B A C | A B C | B C
2. A → a A | e
2. A → a
3. B → b B | e
4. C → c
I
G13: 1. S → A B A C | B A C | A B C | B C
1. S → A A C | A C | C
2. A → a A | a 2. B → b
3. B → b B | e
III
4. C → c
II
G13: 1. S → A B A C | A B C | B A C | B C | A A C | A C | C
2. A → a A | a
3. B → b B | b
4. C → c