-2

I am trying to create a context-free grammar for the language

L = {u2v; u,v E {a,b}*; |u| >= |v|}

however, I can't really understand how to pick up from here.

My idea is that for every a/b character that I generate in u, I should generate another a/b character in the string v. My biggest problem is the symbol 2 there, as I don't know how to add it after doing all of this or how to write a rule saying that it should be skipped.

How can this grammar be constructed?

prkist
  • 431
  • 5
  • 13

1 Answers1

0

A Context Free Grammar would be:

G = ({S,T},{a,b,2,},S,P)
P:
S-> aSa | aSb | bSa | bSb | T
T-> aT | bT | 2
Hassan Abbasi
  • 272
  • 1
  • 3