Consider the language {a n b m c p | n <= p OR m <= p}
{a n b m c p | n <= p OR m <= p}
, create a CFG for this language.
I have started this with S -> aA | aB
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.