Context Free Grammar CFG for your language La = {ai bj ck | i + j = 2k and k >= 1}
.
Below is answer with language L = {ai bj ck | 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 e.g. 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 La
Edit
La = {ai bj ck | i + j = 2k and k >= 1}
.
CFG for La:
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 La:
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