Professional Documents
Culture Documents
For each of the languages below, give a context-free grammar that will generate it.
1. L1 = {an bm ck | n + m = k }
Production Rules
S → aSc
S → S1
S→
S1 → bS1 c
S1 →
2. L2 = {an bm ck | n + k = m }
Production Rules
S → S1 S2
S1 → aS1 b
S1 →
S2 → bS2 c
S2 →
3. L3 = {an bm | m ≤ n ≤ 2m }
Production Rules
S → aSb
S → aaSb
S→
Production Rules
1
S → aSb | aSa | bSa | bSb | c
Production Rules
6. L6 = {an bm ck | n 6= m or m 6= k }
Production Rules
S → S1 S3 | S2 S3 | S4 S5 | S4 S6
Each of the four ‘cases’ are accounted for (from left to right in the above production).
S1 → aS1 b | aS1 | a
S2 → aS2 b | S2 b | b
S3 → S3 c |
S4 → aS4 |
S5 → bS5 c | bS6 | b
S6 → bS6 c | S6 c | c
7. L7 is the complement of language denoted by a∗ b∗ c∗ . Here the alphabet set is Σ = {a, b, c}.
In the complement of the language denoted by a∗ b∗ c∗ , there must be ‘b’ followed later by an ‘a’,
or a ‘c’ followed later by a ‘b’ or an ‘a’...these conditions cause the string to no longer be in a∗ b∗ c∗ ,
since there are characters ‘out of order’ of that grammar...
Note that there can be characters in-between, the ‘following’ character mentioned above does not need to
directly follow the first.
2
Production Rules