Documente Academic
Documente Profesional
Documente Cultură
(a)
1. Introduce
Introduce a new start variable,
where
variable.
2. Eliminate all
rules
, where
and
, where
is the CFG's
variable alphabet.
Remove every rule with
unless
has
already been removed through this process. For example, examine the following grammar
has one
3 rules.
3. Eliminate all unit rules
rules have been removed, you can begin removing unit rules, or rules whose RHS
unless this is a
wit
h
If
, where
, replace
In the grammar
S AB | a
Ab
S, A, a, and b are generating. B is not generating.
Eliminating the productions containing the nongenerating symbols we get
Sa
Ab
Now we see A is not reachable from S, so we can eliminate the second production to
get
Sa
The generating symbols can be computed inductively bottom-up from the set of
terminal symbols.
A unit production is one of the form A B where both A and B are nonterminals.
F I
TF
ET
Are three unit productions.
Unit production F I can be removed by the help of
I a/b/Ia /Ib/I0/I1
and grammar becomes
I a/b/Ia /Ib/I0/I1
F (E)/ a/b/Ia /Ib/I0/I1
TF/T*F
E T/E+T
Now we can eliminate T F, by the help of
F (E)/ a/b/Ia /Ib/I0/I1
And now grammar become
I a/b/Ia /Ib/I0/I1
F (E)/ a/b/Ia /Ib/I0/I1
TT*F/(E)/ a/b/Ia /Ib/I0/I1
E T/E+T
Now let us remove E T by the help
T T*F/(E)/ a/b/Ia /Ib/I0/I1
And finally, unit production free grammar is
I a/b/Ia /Ib/I0/I1
F (E)/ a/b/Ia /Ib/I0/I1
TT*F/(E)/ a/b/Ia /Ib/I0/I1
E E+T/ T*F/(E)/ a/b/Ia /Ib/I0/I1
Q6
(a)
Q7
(a) brain master page 124, Q-21
(b)
(c) brain master page 139, Q-53-v