0

Consider the language {anbmcp | n <= p OR m <= p} , create a CFG for this language.
I have started this with S -> aA | aB, but am unsure how I should go about defining A or B. The "OR" seems quite difficult to incorporate into the language's definition as it doesn't seem necessary to track both n and m and compare them against p, yet I don't know which one I want to track

ffff
  • 2,853
  • 1
  • 25
  • 44
DennisKRQ
  • 175
  • 1
  • 6

1 Answers1

2

In order to maintain that constraint, for every 'a' you need to add a 'c'. Similarly for every 'b' you should add a 'c'.

A -> aAC | aC | B

B -> bB | bC

C -> cC | c

I could be wrong here. But that's how you should think while creating a CFG.

Community
  • 1
  • 1
ffff
  • 2,853
  • 1
  • 25
  • 44