Re: CFG for L(G) and L(G')
- From: torbenm@xxxxxxxxxxxxx (Torben Ægidius Mogensen)
- Date: 23 Feb 2006 12:59:26 +0100
"jason_box" <cppisfun@xxxxxxxxx> writes:
Given a CFG G where epsilon is in L(G), how would you create a new
grammar L(G' = L(G) - epsilon? I know there is a method that allows you
to change a grammar G where epsilon is not part of L(G) and you can get
a equivalent grammar G' having no epsilon production. The question
arises when you have epislon as part of the lanaguage. Thank you for
help in adanced.
If a production has more than two symbols on the RHS, add new
productions to reduce the number. For example, rewrite
N -> ABCD
to
N -> AN'
N' -> BN"
N" -> CD
Then calculate for each nonterminal if it is nullable.
If you have a production N -> AB, where A and B are terminals or
nonterminals, add new productions according to the following rules:
1. If A is a nullable nonterminal, add N -> B
2. If B is a nullable nonterminal, add N -> A
Now remove all empty productions.
Torben
.
- Follow-Ups:
- Re: CFG for L(G) and L(G')
- From: jason_box
- Re: CFG for L(G) and L(G')
- References:
- CFG for L(G) and L(G')
- From: jason_box
- CFG for L(G) and L(G')
- Prev by Date: Re: o-1 Knapsack problem
- Next by Date: revision algorithms
- Previous by thread: CFG for L(G) and L(G')
- Next by thread: Re: CFG for L(G) and L(G')
- Index(es):
Relevant Pages
|