How can I construct a grammar that generates this language? Construct a grammar that generates L:
L = {a^n b^m c^k|k>n, k>m}
I believe my productions should go along this lines:
S-> ABCC
A-> a|aBC|BC
B-> b|bBC
C-> c|Cc
CB->BC
The idea is to start with 2 c and keep always one more c, and then with C->c|Cc ad as much c as i want. How can my production for C remember the numbers of m and n.
One option would be the following: generate a string in which every time you generate a c
, you either
a
to pair it with,b
to pair it with, ora
and a b
to pair it with.This starts off here:
S → X
X → c | MXc | Xc
M → A | B | AB
Bc → bc
Ab → ab
BA → AB
(Note that this is partially incomplete). Here, X expands out to a series of c
's on one side of the string that are paired on the other side of the string with A
s and B
s. The productions for A
s and B
s are there to ensure that they're reordered into the proper order before being expanded.
One case this doesn't consider is what happens if you have a string of the form ancn+k, but that can be fixed as follows:
S → X | Y
X → c | MXc | Xc
M → A | B | AB
Bc → bc
Ab → ab
BA → AB
Y → aYc | Yc | c
Hope this helps!