Hello I would like to ask you this question.
I was supposed to compute (manually) a grammar in Greibach Normal Form, that generates the language
L = {a i b j c k | i + j = 2k and k >= 1}
I really have no idea. Can someone please help me?
Thanks in advance
Chriss
Context Free Grammar CFG for your language L a = {a i b j c k | i + j = 2k and k >= 1}
L a = {a i b j c k | i + j = 2k and k >= 1}
.
Below is answer with language L = {a i b j c k | i + j = k and k >= 1}
L = {a i b j c k | i + j = k and k >= 1}
.
CFG:
S --> aAc | bBc |
A --> aAc | B | ^
B --> bBc | ^
What is GNF?
One important form of CFG is Greibach Normal Form GNF:
A --> aα
Where α ∈ V* (any number of variables including zero)
Note: nul ^
can't be a symbol on RHS of any production accept start symbol S
with constrict that if S --> ^
is a production in grammar then S
can't be appear on RHS of any other production in grammar.
Any CFG can be written in GNF form.
How to convert CFG in GNF?
Note in CFG I written above have nul productions A --> ^
and B --> ^
and a Unit production A --> B
. Unit productions and nul productions are not allowed in GNF form. Although other productions can easily written in GNF form by introduction in GNF productions in grammar eg S --> aAc
can be rewrite as S --> aAC and C --> c
.
So below I am rewriting equivalent CFG for language and removing nul and unit productions called simplified CFG.
Simplified CFG:
S --> aAc | bBc | ac | bc
A --> aAc | bBc
B --> bBc | bc
Now this grammar can easily converted into GNF form by introducing new GNF production C --> c
and replace c
by C
in other production rules.
GFN for language L:
S --> aAC | bBC | aC | bC
A --> aAC | bBC
B --> bBC | bC
C --> c
By mistake I written a wrong grammar I will update answer for language L a
Edit
L a = {a i b j c k | i + j = 2k and k >= 1}
L a = {a i b j c k | i + j = 2k and k >= 1}
.
CFG for L a :
S --> aaAc | bbBc | abBc
A --> aaAc | B | abBc | ^
B --> bbBc | ^
Simplified CFG:
S --> aaAc | bbBc | abBc | aac | bbc | abc
A --> aaAc | bbBc | abBc | aac | abc
B --> bbBc | bbc
GFN for language L a :
Add three new production rules: X --> a
, Y --> b
and Z --> c
.
Change programmer and replace terminal by variables:
S --> aXAZ | bYBZ | aYBZ | aAZ | bYZ | aYZ
A --> aXAZ | bYBZ | aYBZ | aXZ | aYZ
B --> bYBZ | bYZ
X --> a
Y --> b
Z --> c
About Below answer CFG of La = {ai bj ck | i + j = k and k >= 1}
La = {ai bj ck | i + j = k and k >= 1}
is wrong
Your Simplified CFG:
S --> aAc | bBc | ac | bc . A --> aAc | bBc . B --> bBc | bc .
Because the above language L = {ai bj ck | i + j = k and k >= 1}
L = {ai bj ck | i + j = k and k >= 1}
produce the language aabccc
but your Simplified CFG not produce it .
Right CFG is
Simplified CFG
S --> aAc | bBc | ac | bc A --> aAc | bBc | bc | ac B --> bBc | bc
Correct it, Second language has the same problem.
Thanks!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.