-1

I am trying to find the context free grammar for this equation

L = {a ᶦ b ʲ c ᵏ |  i = j or i = k, i, j, k ≥ 0}

I have been able to work out the grammar for when a and b have equal exponent such as

S->ɛ
S->XY
S->ab
S->aXb
Y->cY | ɛ

but I am having troubles when I try to do when a and c have the same exponent, as the b now is on the way. Can someone give me some good hints or corrections?

  • 1
    Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then check the [help/on-topic] to see which questions are on-topic on this site. You might want to delete this question and ask it on https://cs.stackexchange.com/ instead, but check the help pages there first. – Progman Jan 22 '22 at 23:05

1 Answers1

0

S → ab S → aXb means, exactly, that S is an ab surrounded by equal length strings of as and bs.

The ab is completely orthogonal:

  • S → x S → a S b

    x, axb, aaxbb, aaaxbbb, aaaaxbbbb, …

  • S → centre S → a S b

    x, acentreb, aacentrebb, aaacentrebbb, aaaacentrebbbb, …

  • S → ε S → a S b

    ε, ab, aabb, aaabbb, aaaabbbb, …

It works just the same if the thing in the middle is a non-terminal. Or a sequence of terminals and non-terminals. This is one of the ways you can compose grammars.

rici
  • 234,347
  • 28
  • 237
  • 341